0
我在自定義用戶控件中擁有兩個依賴屬性(兩個字符串列表)。對於這些依賴屬性之一的綁定可以在應用程序的生命期中多次更改。當綁定發生變化時,我需要在用戶控件中執行一些操作,並且需要訪問類中的所有依賴項屬性以執行操作。具有依賴項屬性的場景 - 如何彼此訪問
例如,
public class UC:UserControl
{
public List<string> AvailableItems
{
get { return (List<string>)this.GetValue(AvailableItemsProperty); }
set { this.SetValue(AvailableItemsProperty, value); }
}
public static readonly DependencyProperty AvailableItemsProperty = DependencyProperty.Register(
"AvailableItems", typeof(List<string>), typeof(ItemSelectionUserControl), new FrameworkPropertyMetadata(OnAvailableItemsChanged) { BindsTwoWayByDefault = true });
public List<string> SelectedItems
{
get { return (List<string>)this.GetValue(SelectedItemsProperty); }
set { this.SetValue(SelectedItemsProperty, value); }
}
public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
"SelectedItems", typeof(List<string>), typeof(ItemSelectionUserControl), new FrameworkPropertyMetadata { BindsTwoWayByDefault = true });
public static void OnAvailableItemsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
//How to access SelectedItems here??
}
}
麻煩的是,當依賴屬性改變應該是靜態的回調,所以我怎麼能訪問非靜態依賴屬性包裝的功能?或者有沒有其他的方式來做到這一點?
謝謝阿米特。 – Jimmy