Tag: wpf controls

获取WPF控件的当前大小

我的窗口中有图像控件。 此图像控件的大小设置为“自动”。 当我尝试访问时,它返回0.如何查看此控件的实际大小? 它用窗口resize。

将内容包装在stackpanel中

是否可以在stackpanel中包装内容? 我知道我们可以使用WrapPanel代替。 但是出于代码修改的原因,我必须使用Stackpanel。 那么,有没有办法在说出5个项目之后在stackpanel包装中制作物品……谢谢!

c#wpf应用程序中的时钟

我正在研究c#wpf应用程序,我想为我的应用程序添加一个时钟: 如何在我的应用程序中制作该时钟? 如何让我的应用程序时钟没有链接到Windows时钟? 如何在我的应用程序中以不同的样式显示时钟? 如何使它包含日历,时区等…并通过我的应用程序本身修改这些东西? 我可以在与应用程序时钟链接的数据库中制作我的时间戳,以及如何实现这一点?

进度条不递增

我有以下代码读取文件,并在读取时增加te进度条,但我没有在progressBar看到任何活动。 谁能帮助我为什么? progressBar1.Minimum = 0; progressBar1.Maximum = (int)fileStream.Length + 1; progressBar1.Value = 0; using (fileStream) { fileStreamLength = (int)fileStream.Length + 1; fileInBytes = new byte[fileStreamLength]; int currbyte = 0, i = 0; var a = 0; while (currbyte != -1) { currbyte = fileStream.ReadByte(); fileInBytes[i++] = (byte)currbyte; progressBar1.Value=i; } }

在WPF中更改动态创建的按钮背景

我有以下代码来动态创建并向面板添加按钮: StackPanel topPanel=…; Button button=new Button(); button.Content=”New Button “+topPanel.Children.Count; // Set button background to a red/yellow linear gradient // Create a default background brush var bgBrush=new LinearGradientBrush(new GradientStopCollection( new GradientStop[] {new GradientStop(Color.FromRgb(255,255,200),0.5), new GradientStop(Color.FromRgb(255,200,200),0.5)})); // Create a more intense mouse over background brush var bgMouseOverBrush=new LinearGradientBrush(new GradientStopCollection( new GradientStop[] {new GradientStop(Color.FromRgb(255,255,100),0.5), new GradientStop(Color.FromRgb(255,100,100),0.5)})); // Set […]

如何从wpf中的Web浏览器控件获取文档的标题

我在TabControl中创建了一个Web浏览器控件。我想将TabItem的Header设置为Web浏览器的Document标题。 我在WebBrowser的Navigated Event中使用了以下代码 dynamic doc = tabBrowser.Document; //tabBrowser is the name of WebBrowser Control tab.Header = doc.Title; //tab is the name of the Tab Item 但是这段代码不能正常工作。标题仅针对少数网站进行更改。 如何将tabItem的标题设置为文档的标题值? 这是导航function: public void tabBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { urlTextBox.Text = tabBrowser.Source.ToString(); myHistory.addToHistory(tabBrowser.Source.ToString()); BookMarks.addBookmark(tabBrowser.Source.ToString()); dynamic doc = tabBrowser.Document; tab.Header = doc.Title; }

WPF xaml文件中另一个项目中的引用名称空间

我引用了另一个项目的命名空间(类库,所有模型都驻留在其中)。 正如相关问题中所提到的,他们通过将程序集添加到.xaml文件中来解决问题。 但这对我不起作用。 这就是我发帖的原因。 我有2个项目。 WPF项目本身。 类库(这包含所有视图模型) WPF项目引用了类库。(应该在WPF项目的bin中创建这个类库的dll文件) 我想引用类库中的模型。 所以,我做了如下。 …. …. … 但问题仍然存在,这个ProductListVM类(模型)存在于WPFApplication.CommonInterface.Shared.ViewModels名称空间中,它也是public 。 🙂 错误说, The name “ProductListVM” does not exist in the namespace “clr-namespace:WPFApplication.CommonInterface.Shared.ViewModels; assembly=WPFApplication.CommonInterface”. 我还尝试单独构建类库并手动将dll文件添加到WPF项目bin/debug并构建它。 但问题同样存在。 错误列表中还有另一个错误。 Unknown build error, ”clr-namespace:WPFApplication.CommonInterface.Shared.ViewModels; assembly=POS.WPFApplication.CommonInterface’ mapping URI is not valid. Line 7 Position 14.’ D:\Dev\WPFApplication\Views\POSViews\SalesScreen.xaml Error 1 The URI “clr-namespace:WPFApplication.CommonInterface.Shared.ViewModels; assembly=WPFApplication.CommonInterface” is not a […]

如何在可拖动的canvas上制作矩形?

我有这三个函数来触发事件。 我已经有了我需要的静态版本,但我需要它的动态版本。 bool captured = false; double x_shape, x_canvas, y_shape, y_canvas; UIElement source = null; private void MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { source = (UIElement)sender; Mouse.Capture(source); captured = true; x_shape = Canvas.GetLeft(source); x_canvas = e.GetPosition(canvasPreview).X; y_shape = Canvas.GetTop(source); y_canvas = e.GetPosition(canvasPreview).Y; } private void MouseMove(object sender, MouseEventArgs e) { //MessageBox.Show(“test”); if (captured) { double x […]

用户编辑完行后如何获取DataGrid行数据?

我想在用户完成在数据网格中输入行后立即validation用户输入的内容。 我应该查看什么事件,以及如何检索行数据? 或者甚至更好,它必然会受到什么影响?

WPF单击ListBoxItem中的控件不选择ListBoxItem

嗨,我找不到任何类似的问题,所以我发布了新的问题。 在下面的代码中,我使用ListBoxItems创建ListBox控件,每个ListBoxItem包含单选按钮。 当我单击单选按钮时,它会选择,但父ListBoxItem不会(ListBoxItem不会突出显示)。 我该如何解决这个问题?