Skip to content

Instantly share code, notes, and snippets.

@alexdioso
Created August 22, 2011 23:28
Show Gist options
  • Save alexdioso/1163915 to your computer and use it in GitHub Desktop.
Save alexdioso/1163915 to your computer and use it in GitHub Desktop.
Run-time and design-time selection of a ViewModel using only xaml.
<Window Name="mMainView"
x:Class="MyProject.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:MyProject.ViewModels"
mc:Ignorable="d"
Title="My Project" Height="450" Width="800">
<mc:AlternateContent>
<mc:Choice Requires="d">
<Window.Resources>
<vm:MockViewModel x:Key="MainViewModel" />
</Window.Resources>
</mc:Choice>
<mc:Fallback>
<Window.Resources>
<vm:MainViewModel x:Key="MainViewModel" />
</Window.Resources>
</mc:Fallback>
</mc:AlternateContent>
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
DataContext="{StaticResource MainViewModel}">
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment