Tag: wpfdatagrid

如何在DataTemplate中找到一个控件并在WPF中赋值?

我有一个DataTemplate绑定到Grid Group Header Section。 DataTemplate中有四个TextBlock,其中一个TextBlock包含Grid Header Column Value。 现在,我想将此TextBlock值拆分为三个,并将此值分配给Code Behind中的其他三个TextBlock。 可能吗? <!– –> protected void GetAllInfills() { List infillList = new List(); infillList=BLL.GetAllInfills(); if (infillList != null) { grdInfill.ItemsSource = infillList; grdInfill.GroupBy(grdInfill.Columns[“GlassType”], ColumnSortOrder.Ascending); grdInfill.GroupBy(grdInfill.Columns[“GlassDescription”], ColumnSortOrder.Ascending); grdInfill.AutoExpandAllGroups = true; } } 从上面marukup我想访问TextBlock控件,即’ txtdescription ‘,其中包含Grid txtdescription ‘的组头部分值,现在我想将此值int拆分为三个值,即txtdescription.Split(’*’)并赋值到其他三个文本块,即来自代码隐藏的DataTemplate中的txtdesc1,txtdesc2,txtdesc3。

无法在具有DataView实例作为项目源的WPF数据网格中显示数据

我正在使用WPF工具包中的DataGrid对象。 我将DataGrid对象绑定到DataTable实例的默认视图,如以下代码中所声明: WeatherGrid.ItemsSource = weatherDataTable.DefaultView; weatherDataTable有三列。 第一列定义为包含字符串数据类型。 其他两列定义为包含双数据类型。 当应用程序退出调用绑定的函数时,如声明中所表示的那样,DataGrid对象显示第一列的数据,但不显示其他列的数据。 当我在调试器的立即窗口中键入以下内容时: ((DataRowView)WeatherGrid.Items[0]).Row[1] 我得到一个数字,但这与显示的内容不符。 为什么只有第一列可见,我如何才能看到所有数据? 我将在下面的DataGrid对象中留下我的XAML定义:

列出DataGrid中的目录文件

我搜索了很多主题,但无法找到使用WPF DataGrid列出目录中文件名内容的答案。 我能够在ListBox输出内容,但不知道如何将项添加到DataGrid的Column 。 这适用于ListBox string path = “C:”; object[] AllFiles = new DirectoryInfo(path).GetFiles().ToArray(); foreach (object o in AllFiles) { listbox.Items.Add(o.ToString()); } 如何使用DataGrid执行相同的操作? 或者至少将array strings放入DataGrid Column ?

我如何解决这个lambda表达式外部变量问题?

我正在使用PropertyDescriptor和ICustomTypeDescriptor( 仍然 )尝试将WPF DataGrid绑定到一个对象,数据存储在一个Dictionary中。 因为如果你向WPF DataGrid传递一个Dictionary对象列表,它将根据字典的公共属性(Comparer,Count,Keys和Values)自动生成列,我的Person子类为Dictionary,并实现ICustomTypeDescriptor。 ICustomTypeDescriptor定义了一个返回PropertyDescriptorCollection的GetProperties方法。 PropertyDescriptor是抽象的,所以你必须将它子类化,我想我有一个构造函数,它接受Func和一个Action参数,它们委托字典中值的获取和设置。 然后我为字典中的每个Key创建一个PersonPropertyDescriptor,如下所示: foreach (string s in this.Keys) { var descriptor = new PersonPropertyDescriptor( s, new Func(() => { return this[s]; }), new Action(o => { this[s] = o; })); propList.Add(descriptor); } 问题是每个属性得到它自己的Func和Action但它们都共享外部变量s所以尽管DataGrid自动生成“ID”,“FirstName”,“LastName”,“Age”,“Gender”的列,它们都得到了设置为“性别”,这是foreach循环中s的最终静止值。 如何确保每个委托使用所需的字典密钥,即Func / Action实例化时的s值? 非常感谢。 这是我的其余想法,我只是在这里试验这些不是’真正’的类…… // DataGrid binds to a People instance public class People : […]

WPF MVVMLight:基于另一个DataGrid的SelectedItem更新DataGrid

使用MVVMLight开发WPF应用程序。 我的Model由一个Attribute类和一个DataSet类组成,其中一个名为Attributes的ObservableCollection Attributes 。 我的MainViewModel有一个DataSet属性。 在我的MainView ,它的DataContext设置为MainViewModel我有两个DataGrids 。 一个有它的ItemsSource绑定到DataSet.Attributes工作正常: //some DataGrid columns here 我希望第二个DataGrid基于第一个DataGrid的SelectedItem显示一些其他属性,所以我做了以下内容: 1)在MainViewModel添加了Attribute类型的SelectedAttribute属性: private Attribute selectedAttribute; public Attribute SelectedAttribute { get { return selectedAttribute; } set { if (selectedAttribute == value) { return; } selectedAttribute = value; RaisePropertyChanged(() => SelectedAttribute); } } 2)修改了我的第一个DataGrid ,将其SelectedItem绑定到SelectedAttribute : 3) Update 1将第二个DataGrid的ItemsSource设置为SelectedAttribute并创建一个绑定到SelectedAttribute的Categories属性的列,它是ObservableCollection : 4)在我的MainViewModel ,一旦填充了DataSet.Attributes ,我将SelectedAttribute设置为集合中的第一个Attribute (就像测试一样): […]

combobox与WPF DataGrid中的复选框

我需要在WPF的DataGrid中显示带有复选框选项的combobox。 请提供任何解决方案。 我试过下面的代码 它会像这样输出 任何人都可以帮助加载combobox中的项目集合并更正我的代码。 CS代码: private void resultGrid_Loaded(object sender, RoutedEventArgs e) { var programs = new List(); programs.Add(new Programs(“test”, false)); programs.Add(new Programs(“test1”, false)); programs.Add(new Programs(“test2”, true)); //var grid = sender as DataGrid; resultGrid.ItemsSource = programs; Combo.ItemsSource = programs; } 而型号: public class Programs { public Programs(string Program, bool IsChecked) { this.Program = Program; this.IsChecked […]

WPF DataGrid – 如何设置列标题以具有垂直文本?

嗯,实际上从水平旋转-90度就是我的意思。 我需要这样做,因为标题的文本很长但单元格值很短,我想在屏幕上放置很多列。 是否可以轻松完成此操作或者我是否需要首先了解资源和模板? 我不介意“黑客”解决方案!

在WPF中获取数据网格中的多个选定行?

我希望在WPF中获得多个数据网格选择,因为我的业务需求我在数据网格中有一个客户表,允许多个选择和单选按钮(ALL,Selected,All but selected)。 如果单击所选或全部但是已选中,则我必须仅为在数据网格中选择的客户提取数据。 请建议解决方案以获取多个选定的数据网格行。 谢谢。

如何根据绑定值更改WPF数据网格行的图像

我是WPF的初学者。 我有一个数据网格,用于显示带有列定义的消息,如下所示。 数据网格绑定到数据表 现在我需要添加一个标题为“状态”的coulmn。 和内容为图像。 我正在将数据表的“IsRead”列绑定到此列,这样如果IsRead值为False,我需要显示图像unread.png,如果IsRead值为True,我需要显示图像read.png 我该怎么做呢?

WPF Datagrid“全选”按钮 – “全部取消选择”?

我想知道是否可以在数据网格左上角的“全选”按钮中添加function,以便它也可以取消选择所有行? 我有一个方法附加到一个按钮来执行此操作,但如果我可以从全选按钮触发此方法,以保持function在视图的相同部分,这将是很好的。 这个“全选”按钮是否可以添加代码,如果是,那么如何进入按钮? 我找不到任何例子或建议。