WPF Modal window not rendering title area on initial ShowDialog() until mouse move
Chris
0
Reputation points
I'm using .NET Framework6.0 and encountering a strange render issue in a custom WPF modal dialog.
Environment:
- .NET FrameWork4.6
- Windows: Windows 11 64-bit
When I display a window using ShowDialog() in a button click event and the title are doesn't render on initial display, the only occurs occasionally and can't be reliably reproduced.
The phenomenon is as follows:
normal show:
abnormal show:
My UI is as follows. I set property via back code.
<Window x:Class="MessageboxDispalyTesting.TransparentDialog"
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:MessageboxDispalyTesting"
mc:Ignorable="d"
WindowStyle="None"
SizeToContent="WidthAndHeight"
ResizeMode="NoResize"
ShowInTaskbar="False"
Topmost="False"
Title="TransparentDialog"
WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
Background="Transparent"
Height="300" Width="300">
<Border x:Name="GMB_Border" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid x:Name="GMB_Title" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Image x:Name="GIMG_Title" Width="60" Height="60" Margin="-10,0,-10,-10"/>
<Grid Grid.Column="1" Margin="5,0,0,0" >
<TextBlock x:Name="GTXT_Title" HorizontalAlignment="Left" VerticalAlignment="Center" />
<Rectangle x:Name="GRT_Line" Fill="White" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="2" Visibility="Collapsed" Margin="0,0,-25,2"/>
</Grid>
<Image x:Name="GIMG_Title2" Grid.Column="3" Width="40" Height="70" Margin="0,5,5,0" Visibility="Collapsed"/>
<Button x:Name="GMB_Close" Grid.Column="3" Margin="5" Padding="4" />
</Grid>
<AdornerDecorator Grid.Row="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="GMB_ContentPanel" Orientation="Vertical" Margin="10,8,60,10">
<Grid x:Name="GMB_Module"
TextBlock.FontSize="15" TextBlock.FontWeight="Bold" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<Grid x:Name="GMB_Code"
TextBlock.FontSize="15" TextBlock.FontWeight="Bold" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<TextBlock/>
<StackPanel x:Name="GMB_Info" Orientation="Vertical"/>
<TextBlock/>
<TextBlock x:Name="GMB_SolnTxT" TextAlignment="Center"
FontSize="15" FontWeight="Bold" HorizontalAlignment="Left"
VerticalAlignment="Center" />
<StackPanel x:Name="GMB_Soln" Orientation="Vertical"/>
</StackPanel>
</ScrollViewer>
</AdornerDecorator>
<StackPanel x:Name="GMB_Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" Margin="0,5,10,10" />
</Grid>
</Border>
</Window>
```why does this phenomenon occur?
are there any known workarounds to force proper rendering on initial ShowDialog()?
Developer technologies | Windows Presentation Foundation
Sign in to answer