Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- </Grid.RowDefinitions>
- <Button
- Grid.Row="0"
- Height="40"
- Command="{Binding ClickCommand}"
- Content="Click" />
- <ucerControls:FirstUC Grid.Row="1" DataContext="{Binding FirstViewModel}" />
- <ucerControls:SecondUC
- Grid.Row="2"
- DataContext="{Binding SecondViewModel}"
- Visibility="{Binding Visible}" />
- <Button
- Grid.Row="3"
- Height="30"
- Content="{Binding Text}"
- Visibility="{Binding Visible}" />
- </Grid>
- public class MainViewModel:INotifyPropertyChanged
- {
- #region PropertyChangedEventHandler
- /// <summary>
- /// Метод проверяющий изменилось ли свойство
- /// </summary>
- public event PropertyChangedEventHandler PropertyChanged;
- protected virtual void OnPropertyChanged(string propertyName)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- #endregion
- private FirstViewModel _firstViewModel;
- private SecondViewModel _secondViewModel;
- private string _visible;
- public MainViewModel()
- {
- FirstViewModel=new FirstViewModel();
- SecondViewModel=new SecondViewModel();
- Visible = "Collapsed";
- ClickCommand = new Command(arg =>
- {
- Visible =(Visible=="Collapsed")?"Visible":"Collapsed";
- });
- }
- public FirstViewModel FirstViewModel
- {
- get { return _firstViewModel; }
- set { _firstViewModel = value; OnPropertyChanged("FirstViewModel");}
- }
- public SecondViewModel SecondViewModel
- {
- get { return _secondViewModel; }
- set { _secondViewModel = value; OnPropertyChanged("SecondViewModel");}
- }
- public string Visible
- {
- get { return _visible; }
- set { _visible = value; OnPropertyChanged("Visible"); }
- }
- public ICommand ClickCommand { get; set; }
- }
Add Comment
Please, Sign In to add comment