I have a certain SpilitView on the panel of which there is a certain TextBox. And I would like to poke various buttons on the SpilitView content textbox content changed in accordance with my imagination. (here is xaml if I could not explain what it was about)

<SplitView.Pane> <StackPanel> <TextBox Text="ИзмСни мСня Ссли смоТСшь" /> </StackPanel> </SplitView.Pane> <SplitView.Content> <Frame x:Name="MyFrame"/> <!-- ЗдСся Π½Π΅ΠΊΠΈΠΉ Ρ„Ρ€Π΅ΠΉΠΌ с 3 ΠΊΠ½ΠΎΠΏΠΊΠ°ΠΌΠΈ: ТСлтая синяя ΠΈ красная --> </SplitView.Content> 
  • Well, why not bind the text on the textbox to the VM property, and change it as you like. For example, by clicking on the button you can send a command to the VM. - VladD 6:42 pm
  • What is a VM property? @VladD - Denisok
  • Well, I thought you were using the MVVM pattern. Well, if simple, then this is an object that is assigned to your DataContext 'y, and you can bind the properties of UI elements to the properties of this object or its subobjects. If you do not use MVVM, be sure to read how time will be, this is the main pattern in WPF / UWP. - VladD pm
  • If I understood correctly, I partially used it ... I just didn’t know that it was so called ...) - Denisok

1 answer 1

Well, for example, something like that. First, VM define a VM :

 class VM : INotifyPropertyChanged { public VM() { ChangeGreetingCommand = new RelayCommand(_ => Greeting = "Ну Ρ‚Ρ‹ монстр!"); } string greeting = "ИзмСни мСня Ссли смоТСшь"; public string Greeting { get { return greeting; } set { if (greeting != value) { greeting = value; NotifyPropertyChanged(); } } } public ICommand ChangeGreetingCommand { get; } void NotifyPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public event PropertyChangedEventHandler PropertyChanged; } 

The class RelayCommand can be RelayCommand , for example, from here .

Then everything is simple. Install VM in any way as a DataContext 'on your root element (window or whatever it is in UWP). Textbox is defined as

 <TextBox Text="{Binding Greeting}" /> 

Button is defined as

 <Button Text="НаТми мСня, Ссли нС боишься" Command="{Binding ChangeGreetingCommand}"/> 

That seems to be all.