Reputation: 1595
I have two ComboBox
ComboBox1 and ComboBox2, I want to execute ComboBox2 converter whenever ComboBox1 SelectedItem
gets changed, How it can be done in XAML.
So far I have this XAML for ComboBox2:
ItemsSource="{Binding MyItems, Converter={StaticResource MYConverter}, ConverterParameter= {Binding ElementName=comboBox1, Path=SelectedItem,Mode=TwoWay}}"
Upvotes: 1
Views: 111
Reputation: 252
On the code-behind, you could create something like this:
comboBox1.SelectionChanged += new SelectionChangedEventHandler(comboBox1SelectionChanged);
It will generate an event handler that wiil be called by delegate, the handler should look like this:
void comboBox1SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//Your logic here
}
Don’t forget:
u
sing System.Windows;
using System.Windows.Controls;
Upvotes: 0
Reputation: 936
A binding is re-evaluated only when the value of the binding is changed, not the converter parameter, so suppose:
SelectedItem1
property of the ViewModel is bound to ComboBox1
sSelectedItem
property.
SelectedItem2
property of the ViewModel is bound to ComboBox2
s SelectedItem
property.
ComboBox2
s ItemSource
property of the ViewModel is bound to a property on your ViewModel called MyItems
:
Whenever SelectedItem1
is changed, you should raise PropertyChanged
event for MyItems
. This way, the binding is re-evaluated and the converter is executed.
P.S: Please give more context about your questions in the future, e.g. what your ViewModel looks like.
Upvotes: 2