Hi all,
I have a WPF application that is a fullscreen kiosk app. It's actually a pretty complicated app at this point, but here's some code that shows the basic idea. Essentially, whenever the user goes from one screen to the next, there's some serious flicker going on bringing up the new window. In severe cases, the desktop is displayed for a few seconds before the new screen shows up. That doesn't happen in this sample code, because it's so simple, but add a few more buttons and styles and you'll see it.
App.xaml.cs:
public partial class App : Application {
Manager mManager;
public App() {
mManager = new Manager();
Window1 screen1 = new Window1(mManager);
mManager.Screen1 = screen1;
try {
this.Run(screen1);
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
} finally {
Application.Current.Shutdown();
}
}
}
Window1.xaml.cs:
public partial class Window1 : Window {
Manager Manager{get; set;}
public Window1(Manager inManager) {
InitializeComponent();
Manager = inManager;
}
private void OnChangeScreen(object sender, RoutedEventArgs e) {
Manager.OpenScreen2();
}
}
Window2.xaml.cs:
public partial class Window2 : Window {
Manager Manager{get; set;}
public Window2(Manager inManager) {
InitializeComponent();
Manager = inManager;
}
private void OnChangeScreen(object sender, RoutedEventArgs e) {
Manager.OpenScreen1();
}
}
Manager.cs:
public class Manager {
public Window1 Screen1{ get; set;}
public Window2 Screen2{ get; set;}
public Manager(){
Screen1 = new Window1(this);
}
public void OpenScreen2() {
Screen2 = new Window2(this);
Screen2.Show();
if (Screen1 != null) {
Screen1.Hide();
}
}
public void OpenScreen1() {
Screen1 = new Window1(this);
Screen1.Show();
if (Screen2 != null) {
Screen2.Hide();
}
}
}
Window1.xaml (essentially mimicked by window2.xaml):
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1"
WindowStyle="None"
WindowState="Maximized"
Width="1280"
Height="1024"
FontFamily="Global User Interface"
ResizeMode="NoResize">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Name="ChangeScreenButton" Click="OnChangeScreen" Grid.Row="2" Grid.Column="2" Content="Toggle Screen 2"></Button>
</Grid>
</Window>
Interleaving the displays of the two windows (ie, showing window 1 before deleting window 2, etc) does not change the flickering behavior. In this simple app, it would be possible to just hide the other screens that aren't shown, but in the more complicated app, there's just too much state information to manage screen information properly and easily.
Is there some magic codeword or technique to avoid flicker that would work in this simple app that also scales to the more complex app? I'm worried that I'll be forced to rewrite the entire UI at this point to support hiding and showing, and that's just not feasible in my timeframe.
EDIT: I've tried the hide/show thing on some dialogs, and it just doesn't seem to matter. Maybe it's because the main kiosk app is style heavy?