[英]DataGridComboBoxColumn.ItemsSource. Binding vs EditingElementStyle
There are 2 XAML, why the second work, and the first is not? XAML有2个,为什么第二个可以工作,而第一个没有?
cs: CS:
public partial class myClass: Window
{
public static DependencyProperty RoutersPortsViewProperty = DependencyProperty.Register("RoutersPortsView", typeof(DataView), typeof(myClass));
public myClass()
{
DataTable MyTable = new DataTable();
/*here fill MyTable*/
SetValue(RoutersPortsViewProperty, new DataView(MyTable);
InitializeComponent();
}
/*there other code for class*/
}
XAML not work: XAML不起作用:
<Window Name="myName" x:Class="myClass">
<DataGrid>
<DataGrid.Columns>
<DataGridComboBoxColumn DisplayMemberPath="DisplayString"
SelectedValuePath="id"
SelectedValueBinding="{Binding Path=NWPatchPanelID, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
ItemsSource="{Binding Path=RoutersPortsView, ElementName=myName}"/>
</DataGrid.Columns>
</DataGrid>
</Window>
Error: 错误:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. System.Windows.Data错误:2:找不到目标元素的管理FrameworkElement或FrameworkContentElement。 BindingExpression:Path=RoutersPortsView; BindingExpression:Path = RoutersPortsView; DataItem=null; DataItem = null; target element is 'DataGridComboBoxColumn' (HashCode=11022751); 目标元素是'DataGridComboBoxColumn'(HashCode = 11022751); target property is 'ItemsSource' (type 'IEnumerable') 目标属性为“ ItemsSource”(类型为“ IEnumerable”)
XAML work: XAML工作:
<Window Name="myName" x:Class="myClass">
<DataGrid>
<DataGrid.Columns>
<DataGridComboBoxColumn DisplayMemberPath="DisplayString"
SelectedValuePath="id"
SelectedValueBinding="{Binding Path=NWPatchPanelID, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding Path=RoutersPortsView, ElementName=myName}"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
</Window>
Expose your DP in the form : 以以下形式公开您的DP:
public DataView RoutersPortsView
{
get { return (DataView )GetValue(RoutersPortsViewProperty ); }
set { SetValue(RoutersPortsViewProperty , value); }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.