To change UI content in runtime, you can use Binding
. When binded property is changed from the code, it will be displayed to the UI.
<TextBlock Text="{Binding Title}"/>
To notify UI about changes, property must raise PropertyChanged
event from INotifyPropertyChanged
interface or you can use Dependency Property
.
The Binding is working if the property "Title" is in the xaml.cs file or in the Datacontext class from the XAML
.
The Datacontext can be set up in the XAML directly
<Window x:Class="Application.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Application">
<Window.DataContext>
<local:DataContextClass/>
</Window.DataContext>