There are 2 XAML, why the second work, and the first is not?
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:
<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. BindingExpression:Path=RoutersPortsView; DataItem=null; target element is 'DataGridComboBoxColumn' (HashCode=11022751); target property is 'ItemsSource' (type 'IEnumerable')
XAML work:
<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>