使用WPF做的一个模板页示例
下面是项目文件图:
关键代码如下:
<Page x:Class="WpfMasterPageTes.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" ShowsNavigationUI="False"> <Grid> <Border BorderBrush="Aqua" BorderThickness="2"> <DockPanel> <Frame Source="Header.xaml" Height="100" DockPanel.Dock="Top" NavigationUIVisibility="Hidden"/> <Frame Source="Footer.xaml" Height="30" DockPanel.Dock="Bottom" NavigationUIVisibility="Hidden"/> <StackPanel DockPanel.Dock="Left" Width="100" Background="LightPink"> <Label>Master Link</Label> <Button CommandParameter="Content1.xaml" Click="Button_Click">Content 1</Button> <Button CommandParameter="Content2.xaml" Click="Button_Click">Content 2</Button> </StackPanel> <Frame x:Name="myContentFrame" Source="Content1.xaml" NavigationUIVisibility="Hidden"></Frame> </DockPanel> </Border> </Grid> </Page>
C# Code
private void Button_Click(object sender, RoutedEventArgs e) { myContentFrame.Source =new Uri( ((Button)sender).CommandParameter.ToString(),UriKind.Relative ); }
效果图: