[英]How to execute Converter when value of the another control get's changed?
我有兩個ComboBox
ComboBox1和ComboBox2,我想在ComboBox1 SelectedItem
更改時執行ComboBox2轉換器,如何在XAML中完成。
到目前為止,我對於ComboBox2擁有以下XAML:
ItemsSource="{Binding MyItems, Converter={StaticResource MYConverter}, ConverterParameter= {Binding ElementName=comboBox1, Path=SelectedItem,Mode=TwoWay}}"
僅當更改綁定值時才重新評估綁定,而不是轉換器參數,因此,請假定:
SelectedItem1
視圖模型的屬性綁定到ComboBox1
小號SelectedItem
屬性。
SelectedItem2
視圖模型的屬性綁定到ComboBox2
小號SelectedItem
屬性。
ComboBox2
的ViewModel的ItemSource
屬性綁定到ViewModel上名為MyItems
的屬性:
無論何時更改SelectedItem1
,都應引發MyItems
PropertyChanged
事件。 這樣,重新評估綁定並執行轉換器。
PS:請在將來提供有關您的問題的更多背景信息,例如ViewModel的外觀。
在后面的代碼中,您可以創建如下代碼:
comboBox1.SelectionChanged += new SelectionChangedEventHandler(comboBox1SelectionChanged);
它將生成一個事件處理程序,該事件處理程序將由委托調用,該處理程序應如下所示:
void comboBox1SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//Your logic here
}
不要忘記:
ü
sing System.Windows;
using System.Windows.Controls;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.