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
4970
How to set selecteditem in VM code automatically?
posted

I have XamComboBox set in Xaml like:

<ig:XamComboEditor
IsEditable="False"
ItemsSource="{Binding Path=Items,Mode=TwoWay}"
DisplayMemberPath="ItemName"
SelectedItem="{Binding MyEntity.SelectedItem, Mode=TwoWay, ValidatesOnNotifyDataErrors=False}"  />

IN VM, the binding property definened as:

public ObservableCollection<MyObject> Items;
public MyEntity MyEntity;

then in vm code, when data is loaded from DB, I want to set proper data for UI binding to display the data. So what I did is:

MyEntity.SelectedItem = Items.OrderByDescending(x => x.CreatedDate).FirstOrDefault();

but UI did not display the data properly. I can't fire property changed event as SelectedItem is member of MyEntity, not the VM.

How to resolve this problem?