使用WPF做的一个模板页示例

下面是项目文件图:

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 );
 }

  

效果图:

WPF 制作模板页示例

 模板页的另一个例子

 


本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2011/09/14/2176349.html,如需转载请自行联系原作者

相关文章: