Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scenario with dependency properties-how to access each other
- 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??
- }
- }
- public static void OnAvailableItemsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
- {
- UC uc = sender as UC;
- List<string> selectedItems = uc.SelectedItems;
- }
Advertisement
Add Comment
Please, Sign In to add comment