Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1865
Bind XamComboEditor to ObservableCollection?
posted

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.

Parents
No Data
Reply
  • 6365
    Offline posted

    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; }

    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>

    I have attached a sample application that demonstrates the approach from above.

    If you have any questions, please let me know.

    XamDataGrid_ComboEditorBindMVVM.zip
Children