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 feedback.
If you have any questions, please let me know.
Hi - I need to check on this w.r.t my app. I thing your code should work. I will post in update when I get back to that section of my app. Thanks.
I presume you are referring to the SelectedItem property of the XamComboEditor, since the ComboBoxField does not have such property.
I tested the behavior you have described in regards to adding a new record and not having the AccountAttribute property of the DataItem set and I was not able to reproduce it.Both when adding a record through the UI (the AddNew record) and from code-behind (for testing purpose), the AccountAttribute of the DataItem is successfully set.When working with class types (such as AccountAttribute), in order to compare different instances, it is good for us to override the Equals and GetHashCode methods. This way we will be able to compare the objects by their content or as we desire.
public class AccountAttribute{ ... public override bool Equals(object obj) { var other = obj as AccountAttribute; if (other == null) return false; return this.AccountValue.Equals(other.AccountValue) && this.AccountId.Equals(other.AccountId); } public override int GetHashCode() { return base.GetHashCode(); }}
public override bool Equals(object obj) { var other = obj as AccountAttribute; if (other == null) return false; return this.AccountValue.Equals(other.AccountValue) && this.AccountId.Equals(other.AccountId); }
public override int GetHashCode() { return base.GetHashCode(); }}
I have attached a sample application that demonstrates the approach from above.
Well, the other pending issue is with using property SelectedItem of the ComboBoxField.
Binding SelectedItem to DataItem.AccountAttribute works. However, when I add a new row, the selected AccountAttribute from the combo-box (the combo is populated with a collection of AccountAttribute) is not saved to the AccountAttribute property of the underlying DataItem.
I don't mind using code-behind to do this.
In code-behind if I could just say:
Item.AccountAttribute = <the AccountAttribute selected in the combo-box> // this is not happening automatically !!!
Or something like
Item.AccountAttribute = MyCombo.SelectedItem As AccountAcctribute
I believe this thread can help other people looking for a similar solution.