I’m trying to bind data from a model to the Text property of a TextBlock on a DialogBox. But strangely, no text is displayed.
I have the same principle on a usercontrol which works perfectly.
ViewModel
LogEvents.Add("Server Name : " + Prestage.ServerName);
var dialog = new DialogBox(Prestage.ServerName);
bool? result = dialog.ShowDialog();
View
<Window x:Class="PRESTAGE.Views.DialogBox"
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:PRESTAGE.Views"
mc:Ignorable="d"
Title="DialogBox" Height="150" Width="400" WindowStyle="None" WindowStartupLocation="CenterScreen" Background="Transparent" ResizeMode="NoResize" MouseDown="Window_MouseDown" AllowsTransparency="True">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="IsEnabled" Value="True"/>
<Setter Property="Background" Value="#FFECE1E1"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FF022A79"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Border CornerRadius="12" BorderThickness="2" BorderBrush="#FF022A79">
<Border.Background>
<ImageBrush ImageSource="/Images/banner_prestage.png"
Stretch="Uniform" Opacity="1"/>
</Border.Background>
<Border CornerRadius="10"
BorderThickness="0"
Opacity="0.95">
<Border.Background>
<LinearGradientBrush StartPoint="0,1" EndPoint="0,5">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel >
<StackPanel Margin="0,20,0,0">
<TextBlock Text="Would you like to change the server name?" HorizontalAlignment="Center" Foreground="#FF022A79"></TextBlock>
</StackPanel>
<StackPanel Margin="0,20,0,0">
<TextBlock Text="{Binding Path=Prestage.ServerName, NotifyOnTargetUpdated=True}" HorizontalAlignment="Center" Foreground="#FF022A79"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="48" Margin="0,20,0,0">
<StackPanel VerticalAlignment="Center" Width="242">
<Button x:Name="Oui" Width="226" Height="30" Content="OUI" HorizontalAlignment="Right" Cursor="Hand" Margin="0,0,9,0" Click="Oui_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Width="73" Height="30" CornerRadius="10" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Width="158">
<Button x:Name="Non" Width="73" Height="30" Content="NON" HorizontalAlignment="Right" Cursor="Hand" VerticalAlignment="Center" Click="Non_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Width="73" Height="30" CornerRadius="10" Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</Border>
</Grid>
</Window>
When the DialogBox is loaded, it does not display the server name. The frame is empty, so you can’t see anything apart from the question and the buttons.
On the other hand, the Log does display this same Prestage.ServerName model data
Thank you in advance for your help