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

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.65 KB  |  hits: 14  |  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. Usercontrol databinding property changed MVVM
  2. public class MyControl : UserControl
  3. {
  4. ....
  5. ....
  6. ....
  7. ....
  8.  
  9.         public ViewStyles CurrentView
  10.         {
  11.             get { return (ViewStyles)GetValue(CurrentViewProperty); }
  12.             set
  13.             {
  14.                 SetValue(CurrentViewProperty, value);
  15.                 UpdateView();
  16.             }
  17.         }
  18.         public static readonly DependencyProperty CurrentViewProperty = DependencyProperty.Register("CurrentView", typeof(ViewStyles), typeof(ComboView));
  19.  
  20. ....
  21. .....
  22. .....
  23. .....
  24. }
  25.        
  26. <Views:MyControl Grid.Column="1" Grid.Row="1" Height="505" HorizontalAlignment="Left" Margin="2,0,0,0" Name="comboView1" VerticalAlignment="Top" Width="983"
  27.                  ViewStyle="{Binding Path=CurrentView}" BorderThickness="5" BorderBrush="Black" ItemsSource="{Binding Path=Images}"
  28.                  SelectedIndex="{Binding Path=CurrentIndex}" Foreground="White"
  29.  
  30. </Views:MyControl>
  31.        
  32. <ComboBox Margin="0,3,1,0" Width="178" HorizontalAlignment="Right" Name="ViewDDBox" FontSize="13" Foreground="#FFF6F3F3" Background="#FF444444"
  33.           BorderThickness="2" Height="23" VerticalAlignment="Top" Grid.Column="1"
  34.           ItemsSource="{Binding Path=ViewTypes}" IsEnabled="True" SelectedValue="{Binding Path=CurrentView, Mode=TwoWay}">
  35.          </ComboBox>
  36.        
  37. public static DependencyProperty CurrentViewProperty =
  38.     DependencyProperty.Register("CurrentView", typeof(ViewStyles), typeof(ComboView),
  39.     new FrameworkPropertyMetadata(CurrentViewPropertyChanged));
  40.  
  41. private static void CurrentViewPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  42. {
  43.     MyControl mc = (MyControl)d;
  44.     mc.UpdateView();
  45. }