I am trying to modify a TextBlock from a WPF code. I have the following MainWindow XAML :
<Window x:Class="ChatServer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ChatServer"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="Serveur de chat" Height="450" Width="800">
<Grid x:Name="Grille">
<DockPanel x:Name="DockP" LastChildFill="False">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="5,5,0,0" >
<Border BorderThickness="1" BorderBrush="Blue" DockPanel.Dock="Left" Height="20" Width="380">
<TextBlock HorizontalAlignment="Center" >Statut du Serveur</TextBlock>
</Border>
<Border BorderThickness="1" BorderBrush="Blue" DockPanel.Dock="Right" Height="20" Width="380">
<TextBlock HorizontalAlignment="Center">Gestion des Clients</TextBlock>
</Border>
</StackPanel>
<StackPanel x:Name="DataZ" Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="5,0,0,0" >
<StackPanel x:Name="Server" Orientation="Vertical" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="0,0,0,0">
<Border BorderThickness="1" BorderBrush="Blue" DockPanel.Dock="Left" Width="380">
<TextBox Name="ServerStatus" HorizontalAlignment="Center" VerticalAlignment="Top" Height="30" Width="380" Text="Serveur éteint" Background="#FFB0B0" TextAlignment="Center"/>
</Border>
<Border x:Name="ServerBorder" BorderThickness="1" BorderBrush="Blue" DockPanel.Dock="Left" Height="350" Width="380">
<StackPanel x:Name="SP" Orientation="Vertical" DockPanel.Dock="Top" Margin="0,0,0,0">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,0">
<Button Content="Démarrer" Height="20" Width="60" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,10,10" Click="Demarre"/>
<Button Content="Arrêter" Height="20" Width="60" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10,10,10,10" Click="Arrete"/>
</StackPanel>
<Border x:Name="LogBorder" BorderThickness="3" BorderBrush="Green" DockPanel.Dock="Left" Height="300" Margin="3,3,3,3">
</Border>
</StackPanel>
</Border>
I would like to add a Textblock inside the "LogBorder" Border (the last one). Here is the code (not working) :
public MainWindow()
{
InitializeComponent();
void CreateServerLogText()
{
TextBlock ServerLog = new TextBlock();
// <Border x:Name="LogBorder" BorderThickness="3" BorderBrush="Green" DockPanel.Dock="Left" Height="300" Margin="3,3,3,3">
// <TextBlock x:Name="ServerLog" Text="Logs du serveur" TextWrapping="Wrap"/>
// </ Border >
Grille.LogBorder.Child = ServerLog; // NOT WORKING
// Grille.DockP.DataZ.Server.ServerBorder.SP.LogBorder.Children.Add(ServerLog); // NOT WORKING
}
CreateServerLogText();
}
How do you "navigate" inside the XAML tree to add or modify content inside StackPanel and Border ?