【发布时间】:2009-03-13 18:13:34
【问题描述】:
我是 XAML/WPF 的新手,遇到了这个奇怪的问题:
我有一个列表视图,我为其设置了一个数据源。 DataSource 是“CatalogPartRows”的数组列表。我在代码中创建我的列。然后我设置他们的单元格模板(我的一些列包含组合框和复选框)。我的问题是我需要在“CatalogPartRow”类中调用一个函数来获取我需要在单元格中设置的字符串。
这是我尝试使用的代码:
// THIS DOES NOT WORK
//
ObjectDataProvider ODP = new ObjectDataProvider();
ODP.MethodName = "PropertyValueAsString";
ODP.MethodParameters.Add(PropertyName);
ODP.ObjectType = typeof(CatalogPartRow);
Binding DataBindingText = new Binding();
DataBindingText.Source = ODP;
// THIS WORKS
//
//String BindingPathText = /*NOXLATE*/"PropertyValues[" + CPR.IndexOf(PropertyName) + /*NOXLATE*/"]";
//Binding DataBindingText = new Binding(BindingPathText);
FrameworkElementFactory TextBlockElement = new FrameworkElementFactory(typeof(TextBlock));
TextBlockElement.SetBinding(TextBlock.TextProperty, DataBindingText);
FrameworkElementFactory PropertyColumnElement = new FrameworkElementFactory(typeof(Grid));
PropertyColumnElement.AppendChild(TextBlockElement);
DataTemplate DT = new DataTemplate();
DT.VisualTree = PropertyColumnElement;
GVC.CellTemplate = DT;
我的方法正确吗?
CPR = CatalogPartRow
GVC = GridViewColumn
谢谢, 拉吉。
【问题讨论】:
标签: wpf data-binding xaml objectdataprovider