I am using MVVM. My VM has two properties (1) [Data] which returns ObservableCollection<Account> and (2) [AccountAttributes] which returns ObservableCollection<AccountAttribute>.
I View's code behind DataContext set to above class. [Data] is bound to xamDataGrid and it works fine. I want to bind an property in [AccountAttributes] to XamComboEditor which is linked to a column in xamDataGrid. What is the exact syntax in XAML? If I change [AccountAttributes] to List<string> it works fine but want it to be an ObservableCollection.
Thanks.
Hello Jay,
Thank you for the implementation description you have provided.
Presuming that you would like to bind an ObservableCollection of class instances to the XamComboEditor when using MVVM, you can specify the display and value values that will be used for the binding. (DisplayMemberPath and ValuePath properties of the editor)
C#:
public class AccountAttribute{ public int AccountValue { get; set; }} public ObservableCollection<AccountAttribute> AccountAttributes { get; set; }
public ObservableCollection<AccountAttribute> AccountAttributes { get; set; }
XAML:
<Style TargetType="igE:XamComboEditor"> <Setter Property="ItemsSource" Value="{Binding Path=DataContext.AccountAttributes, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" /> <Setter Property="ValuePath" Value="AccountValue" /> <Setter Property="DisplayMemberPath" Value="AccountValue" /></Style>
If you have any questions, please let me know.
Thanks, your syntax works perfect.
One more help please: I have a couple of events on the grid like xgrdMain_RecordUpdated. How do I access the SelectedItem of the above combo-box in code behind?
In your example above, I get the AccountValues in the drop-down and in the associated grid column but I also want to know the AccountId of the SelectedItem in code behind?