0

Here I checked both ItemSource and SelectedItem and they both have the values I want. 'Tedarikciler' comes from database so it is an ObservableCollection which has a list of 'DynamicProxy.Tedarikci'. The type of SeciliIplik.Tedarikci is also 'DynamicProxy.Tedarikci. But no item is selected when I run the code. I'm sure that both items are binded correctly.

<ComboBox materialDesign:HintAssist.Hint="Tedarikçi Seçin" ItemsSource="{Binding Tedarikciler}" SelectedItem="{Binding SeciliIplik.Tedarikci}" DisplayMemberPath="Adi"/>

It seems like it's a reference problem but is there ant way to achive this.

Thanks in advance

1 Answers1

0

The instance returned by the SeciliIplik.Tedarikci property must be present in the collection returned by the Tedarikciler property, e.g.:

SeciliIplik.Tedarikci = Tedarikciler.FirstOrDefault();

The other option is to override the Equals method of the Tedarikci type.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thank you for your answer. I know it must be present in the collection but they both come from the database. I have two tables one is `Tedarikci` and the other one is `Iplik`. Every `Iplik` has a `Tedarikci`. So `SeciliIplik.Tedarikci` should be present in the collection. Because the type of `SeciliIplik` is `Iplik`. But your second suggestion can be work for me I'll try this. – Yekta Mirkan May 01 '18 at 09:33
  • Whether the objects "come from the database" or somewhere else doesn't matter. It needs to be the very same object reference. Did you try my second suggestion or what happened? – mm8 May 04 '18 at 14:07