How would I go about switching the main display XAML page that gets used in an XBAP. The only different is I want a larger mode and a smaller mode, but with the same controls (some hidden).
In your App.xaml.cs file, you can programmatically change which Window.xaml file you want to show on startup. Here is an over-simplified example.
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
System.Windows.Window startupWindow = null;
if(useLargeMode)
{
startupWindow = new LargeMainWindow();
}
else
{
startupWindow = new SmallMainWindow();
}
window.Show();
}
You can also do this by changing the StartupUri in your App.xaml file but that is obviously going to be harder to change at runtime.
<Application x:Class="Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml" /> <!-- change this -->
I've haven't tried binding to a property in the application declaration in the XAML, but VS 2010 doesn't complain about this. My concern would be that the app had it's datacontext set early enough for this to work correctly. Give it a try and let us know how it works. :)
<Application x:Class="Main.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="{Binding StartupWindow}">