Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Scenario with dependency properties-how to access each other
  2. public class UC:UserControl
  3. {
  4.  public List<string> AvailableItems
  5.         {
  6.             get { return (List<string>)this.GetValue(AvailableItemsProperty); }
  7.             set { this.SetValue(AvailableItemsProperty, value);  }
  8.         }
  9.         public static readonly DependencyProperty AvailableItemsProperty = DependencyProperty.Register(
  10.           "AvailableItems", typeof(List<string>), typeof(ItemSelectionUserControl), new FrameworkPropertyMetadata(OnAvailableItemsChanged) { BindsTwoWayByDefault = true });
  11.  
  12.         public List<string> SelectedItems
  13.         {
  14.             get { return (List<string>)this.GetValue(SelectedItemsProperty); }
  15.             set { this.SetValue(SelectedItemsProperty, value); }
  16.         }
  17.             public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register(
  18.               "SelectedItems", typeof(List<string>), typeof(ItemSelectionUserControl), new FrameworkPropertyMetadata { BindsTwoWayByDefault = true });  
  19.  
  20.  public static void OnAvailableItemsChanged(DependencyObject sender,  DependencyPropertyChangedEventArgs e)
  21.         {
  22.            //How to access SelectedItems here??
  23.         }
  24.  
  25.     }
  26.        
  27. public static void OnAvailableItemsChanged(DependencyObject sender,  DependencyPropertyChangedEventArgs e)
  28.         {
  29.            UC uc = sender as UC;
  30.            List<string> selectedItems = uc.SelectedItems;
  31.         }