I create separate Window, design it with XAML and when I invoke ShowDialog from main form it seems like my dialog (Window) blinks once and then shows itself. Is it a common behavior? I didn't notice that in while working with Windows Forms. I also ran application on another computer, and get the same thing. It bothers me, cause I was developing a simple game, and it's not the effect I would like users to experience.
+1
A:
No. Blinking on ShowDialog is not a common behaviour. Could you first try with an empty Window:
new Window().ShowDialog();
in order to see if the problem persists?
Aside from the main topic, WPF/XAML might be not the proper technology for a complicated game due to performance reasons (although for a simple one must be OK).
Vlad
2010-10-17 13:24:04
No, I don't get it with an empty Window. So, it could be because of the window design? It is a static game (Boggle), I thought it will work fine... And it works, besides this issue.
sokolovic
2010-10-17 14:04:20
Well, then I would suppose adding the items to your dialog one by one (starting with an empty dialog) in order to see which of them causes the problem.
Vlad
2010-10-17 14:14:20
A:
It is not a complicated dialog, considering the design. It contains just label and button. Here is one sample:
<Window x:Class="A_Boggle.Info"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Info" Height="300" Width="670" AllowsTransparency="True" WindowStyle="None" Background="Transparent" BorderBrush="Transparent" Foreground="Transparent" ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Closing="Window_Closing">
<Grid>
<Border Background="Transparent" Visibility="{Binding Visibility}">
<Border BorderBrush="#FF7C4400" BorderThickness="4"
CornerRadius="10,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Center" Height="177.5" Width="596.25">
<Border.Background>
<RadialGradientBrush Center="0.5,0.5" GradientOrigin="0.5,0.5" RadiusX="0.479" RadiusY="0.524">
<GradientStop Color="#FFF58611" Offset="0"/>
<GradientStop Color="#FFF58611" Offset="0.11798000335693359"/>
<GradientStop Color="#FFE9B231" Offset="1"/>
</RadialGradientBrush>
</Border.Background>
<Border.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Opacity="0.5" Direction="270" ShadowDepth="0.7" />
</Border.BitmapEffect>
<Grid>
<Separator Height="20" Name="separator1" Margin="8.75,0,6.25,45" VerticalAlignment="Bottom" />
<Button Style="{DynamicResource OrangeButton}" Margin="406.25,0,6.25,6" Height="37.75" VerticalAlignment="Bottom" FontSize="16" Name="dialogButton" Click="dialogButton_Click"></Button>
<Label FontFamily="Resources/#French Grotesque" FontSize="20" Foreground="#FF7C4400" Margin="8.75,20,6.25,71.25" Name="messageLabel"></Label>
</Grid>
</Border>
</Border>
</Grid>
sokolovic
2010-10-17 15:33:06
Could you try to remove `Visibility="{Binding Visibility}"` for test? This seems a little bit suspicious to me. (Sorry, I don't have my compiler at home, so I cannot test it myself) If this won't help, maybe you can try to remove all the transparency-related things (and in general restore the default window style)?
Vlad
2010-10-17 15:37:14
I did, and the problem remains.Could this be the reason: in the main frame, I have a Windows Forms control inside a Windows Forms Host. It has overriden OnPaint method. When I did debuging, I saw that OnPaint is invoked to often... After every dialog is display, OnPaint is invoked. Maybe that could be the reason for such behaviour?
sokolovic
2010-10-17 15:41:20
Well, Windows Forms' `OnPaint` should be perhaps internal to the Windows Forms part of the UI.
Vlad
2010-10-17 15:46:50
Does this code blink: <Window x:Class="A_Boggle.Info" xmlns="..."xmlns:x="..." Title="Info" Height="300" Width="670" ResizeMode="NoResize" Closing="Window_Closing"> <Grid> <Border> <Border BorderBrush="#FF7C4400" BorderThickness="4" CornerRadius="10,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Center" Height="177.5" Width="596.25"> </Border> </Border> </Grid> </Window> ?
Vlad
2010-10-17 15:49:21
You said that you had a Windows Forms control with overridden OnPaint. I assumed that it couldn't be the reason for the blinking, as the blinking is in WPF part of your application.
Vlad
2010-10-17 16:09:53
Okay, nice. If that does not blink, let's try to add the same transparency attributes to the Window: <Window x:Class="A_Boggle.Info" Title="Info" Height="300" Width="670" AllowsTransparency="True" WindowStyle="None" Background="Transparent" BorderBrush="Transparent" Foreground="Transparent" ShowInTaskbar="False" ResizeMode="NoResize" Closing="Window_Closing"><Grid><Border><Border BorderBrush="#FF7C4400" BorderThickness="4" CornerRadius="10,0,10,0" VerticalAlignment="Center" HorizontalAlignment="Center" Height="177.5" Width="596.25"></Border></Border></Grid></Window>. Does it blink now?
Vlad
2010-10-17 16:12:47
Okay. Does it blink if you add back `Border.Background` and `Border.BitmapEffect`?
Vlad
2010-10-17 16:34:38
Strange! What in the style `OrangeButton`? Try to remove everything except the button. We are on the right way :-)
Vlad
2010-10-17 18:31:32
When I remove everything, it blinks. Only button is shown, with no border around dialog or anything. But button blinks when dialog is shown.
sokolovic
2010-10-17 20:48:06
Okay, not so many properties left :-) Which of them causes the problem? Does it blink without _any_ properties?
Vlad
2010-10-17 21:15:52
Removed all windows properties; only one button is inside dialog. And it blinks SOMETIMES (not everytime, like before). It blinks if I click button on the main form that displays dialog too quickly.
sokolovic
2010-10-17 21:31:56
Can you post the reduced code? By the way, is there anything special in the `A_Boggle.Info`'s constructor? Or in the code which invokes the `ShowDialog`?
Vlad
2010-10-17 21:42:28
The only "special" detail is that Info dialog is shown from another dialog (Main Menu). For example, I have a Main Menu dialog with Credits button; after user presses the button, Main Menu dialog is closed and Info dialog is shown.
sokolovic
2010-10-17 21:55:51
Well, nothing special indeed :-( Did you remove the Button's properties as well?
Vlad
2010-10-17 21:59:28
Yep! Removed all button and windows properties, and still get it. Hm... Anyway, thanks for help, I bothered you for couple of hours! :)
sokolovic
2010-10-17 22:04:14