Hi,
I have a xamlDataGrid for which the datacontext is of different datatypes.It can be even a enumnum values. Set of datatemplates are defined which is of different datatypes.
On selection of a specific datatype on the grid, respective datatemplate is populated.
For enum types,the template has a combox box as shown in the snippet. When a particular row is selected (on selected property change) which is of the type enum,it should populate all the enum values.When a value is selected it should be updated since there is a two way binding.But when I select a particular value from the drop down, that value is shown in all the rows which is of the type Enum. Enum values for each row differs based on the component selected. The following is the snippnet.Values are binded to the dropdown,but the selected value is not being set back to the source. Only the selected value should be bound to that row.On selecting a value,its value should be set back to the source.Please provide the needful since this will be very useful for project and is on urgent basis.
<DataTemplate x:Key="enumTemplate"> <igEditors:XamComboEditor BorderThickness="0" DropDownButtonDisplayMode="OnlyInEditMode" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedProperty.SourceValues}" DisplayMemberPath="EnumName" SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedProperty.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEditable="false" ValuePath="EnumID"></DataTemplate>
Thanks
Deepa
Hello Deepa,
If this template is being used on each row then you are binding the SelectedItem of each XamComboEditor to one property. So if one XamComboEditor makes a selection than it will change every other control that is bound to that one property. This is why all the rows of type Enum are being changed. Each XamComboEditor needs to bind to the Enum property in your row data, not the UserControl's DataContext.SelectedProperty. Does your row data have an Enum property? If so, change your SelectedItem binding to something like this:
"{Binding Path=DataItem.MyEnumProperty}"
If your DataTemplate is inside the row then it's DataContext should be a DataRecord. Inside DataRecord there is a DataItem property which is your data object.