Jose_Minglein
Jose_Minglein

Reputation: 33

WPF ComboBox Master - Slave

I have 2 combobox master-slave in this way:

<ComboBox ItemSource="{Binding MySource}" SelectedItem="{Binding MySelectedItem}" DisplayMemberPath="Description" />
<ComboBox ItemSource="{Binding MySelectedItem.Items}" IsSynchronizedWithCurrentItem="{x:Null}" />

But when I select one item of first combobox which it has empty list of Items after I have selected one of them with Items and selected item in second combobox. The text in second combobox is not empty. I have tried with IsSynchronizedWithCurrentItem="False" too.

What is the problem?

Upvotes: 0

Views: 252

Answers (2)

Jose_Minglein
Jose_Minglein

Reputation: 33

I have found the problem, it was that I have associated a command with interactivity in the combobox and this was catching an exception and didn't continue with the execution.

Upvotes: 0

Gaston Siffert
Gaston Siffert

Reputation: 372

I am not sur to understand what you are trying to say... But I am pretty sur that you didn't notify a PropertyChanged after modify your "MySelectedItem" and you forget the mode=TwoWay...

If you want to use the SelectedItem in your ViewModel:

Xaml:

<ComboBox ItemSource="{Binding MySource}" SelectedItem="{Binding MySelectedItem, mode=TwoWay}" DisplayMemberPath="Description" />
<ComboBox ItemSource="{Binding MySelectedItem.Items}"/>

ViewModel:

private YourItemType _mySelectedItem;
public YourItemType MySelectedItem
{
 get { return (_mySelectedItem);}
set
{
if (_mySelectedItem != value)
{
 _mySelectedItem = value;
if (PropertyChanged != null)
   PropertyChanged(this, new PropertyChangedEventArgs("MySelectedItem"));
}
}

}

If you just want to do a filtering:

<ComboBox ItemSource="{Binding MySource}" DisplayMemberPath="Description" name="source"/>
<ComboBox ItemSource="{Binding SelectedItem.Items, ElementName=source}"/>

Upvotes: 1

Related Questions