Guest User

Untitled

a guest
Nov 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <Grid>
  2. <Grid.RowDefinitions>
  3. <RowDefinition Height="Auto" />
  4. <RowDefinition Height="Auto" />
  5. <RowDefinition Height="Auto" />
  6. <RowDefinition Height="Auto" />
  7. </Grid.RowDefinitions>
  8. <Button
  9. Grid.Row="0"
  10. Height="40"
  11. Command="{Binding ClickCommand}"
  12. Content="Click" />
  13. <ucerControls:FirstUC Grid.Row="1" DataContext="{Binding FirstViewModel}" />
  14. <ucerControls:SecondUC
  15. Grid.Row="2"
  16. DataContext="{Binding SecondViewModel}"
  17. Visibility="{Binding Visible}" />
  18. <Button
  19. Grid.Row="3"
  20. Height="30"
  21. Content="{Binding Text}"
  22. Visibility="{Binding Visible}" />
  23. </Grid>
  24.  
  25. public class MainViewModel:INotifyPropertyChanged
  26. {
  27.  
  28. #region PropertyChangedEventHandler
  29. /// <summary>
  30. /// Метод проверяющий изменилось ли свойство
  31. /// </summary>
  32. public event PropertyChangedEventHandler PropertyChanged;
  33. protected virtual void OnPropertyChanged(string propertyName)
  34. {
  35. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  36. }
  37. #endregion
  38.  
  39. private FirstViewModel _firstViewModel;
  40. private SecondViewModel _secondViewModel;
  41. private string _visible;
  42.  
  43. public MainViewModel()
  44. {
  45. FirstViewModel=new FirstViewModel();
  46. SecondViewModel=new SecondViewModel();
  47. Visible = "Collapsed";
  48.  
  49. ClickCommand = new Command(arg =>
  50. {
  51. Visible =(Visible=="Collapsed")?"Visible":"Collapsed";
  52. });
  53. }
  54.  
  55. public FirstViewModel FirstViewModel
  56. {
  57. get { return _firstViewModel; }
  58. set { _firstViewModel = value; OnPropertyChanged("FirstViewModel");}
  59. }
  60.  
  61. public SecondViewModel SecondViewModel
  62. {
  63. get { return _secondViewModel; }
  64. set { _secondViewModel = value; OnPropertyChanged("SecondViewModel");}
  65. }
  66.  
  67. public string Visible
  68. {
  69. get { return _visible; }
  70. set { _visible = value; OnPropertyChanged("Visible"); }
  71. }
  72.  
  73. public ICommand ClickCommand { get; set; }
  74. }
Add Comment
Please, Sign In to add comment