WPF使用Page创建显示不同控件的程序
2013-07-23 21:53
489 查看
1. 测试环境
WIndows XP/7 + VS2010
2. 操作步骤
1) 创建主Window的XAML文件
2)创建page1
3)创建page2
4修改主窗体的cs文件
WIndows XP/7 + VS2010
2. 操作步骤
1) 创建主Window的XAML文件
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ee="http://schemas.microsoft.com/expression/2010/effects" mc:Ignorable="d" x:Class="UsePageShowControl.MainWindow" x:Name="Window" Title="UsePageShowControl" Width="640" Height="400" ResizeMode="CanMinimize" Background="White"> <Grid x:Name="LayoutRoot"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="3*"/> </Grid.ColumnDefinitions> <StackPanel Margin="3" Grid.Column="0" ButtonBase.Click="Button_Click"> <StackPanel.Effect> <ee:BloomEffect BloomIntensity="2" BaseSaturation="0" BaseIntensity="1" BloomSaturation="3" Threshold="0.2"/> </StackPanel.Effect> <Button x:Name="FirstPage" Content="第一个Page" Margin="1" Height="30" FocusVisualStyle="{x:Null}"/> <Button x:Name="SecondPage" Content="第二个Page" Margin="1" Height="30"/> </StackPanel> <Frame x:Name="PageContext" Grid.Column="1" BorderBrush="Blue" BorderThickness="1" NavigationUIVisibility="Hidden"/> </Grid> </Window>
2)创建page1
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="UsePageShowControl.Page1" x:Name="Page" WindowTitle="Page" FlowDirection="LeftToRight" Width="450" Height="400" WindowWidth="640" WindowHeight="400"> <Grid x:Name="LayoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="3*"/> </Grid.RowDefinitions> <ComboBox Grid.Row="0" Height=" 25"/> <ComboBox Grid.Row="1" Height=" 25"/> </Grid> </Page>
3)创建page2
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="UsePageShowControl.Page2" x:Name="Page" WindowTitle="Page" FlowDirection="LeftToRight" Width="450" Height="400" WindowWidth="640" WindowHeight="480"> <Grid x:Name="LayoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="2*"/> </Grid.RowDefinitions> <Button Grid.Row="0" Height="30"/> <Button Grid.Row="1" Height="30"/> </Grid> </Page>
4修改主窗体的cs文件
using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace UsePageShowControl { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); // 在此点下面插入创建对象所需的代码。 } private void Button_Click(object sender, RoutedEventArgs e) { Button button = (Button)e.Source; if (button.Content.ToString() == "第一个Page") { //this.PageContext.Content = new Page1(); this.PageContext.Source = new Uri("Page1.xaml", UriKind.Relative); } else { this.PageContext.Source = new Uri("Page2.xaml", UriKind.Relative); } } } }
相关文章推荐
- WPF使用Page创建显示不同控件的程序
- [原译]如何创建WPF用户控件&在WPF项目中使用
- MFC中使用控件CEdit创建一个记事本小程序
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- [转载]DrawMe - 使用WPF/WCF创建的网络白板聊天程序
- TextOut 使用创建字体的方法不同造成不同的显示结果
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- Metro之GridView控件的使用-绑定不同的模板样式显示
- 同一个窗口中不同的按钮控件使用同一个storyboard的方法(WPF)
- MFC小程序003------MFC使用WebBrowser组件,在对话框中创建滚动视图,动态创建一个静态文本控件并设置鼠标单击的消息响应
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- 包含别人的dll,然后我们用类库再次封装成dll的时候的注意事项;源文件与模块生成时的文件不同;创建调试信息文件 ··PDB时发生意外的错误,进程无法访问文件,因为另一个程序正在使用此文件
- [WPF系列]-使用Binding来同步不同控件的Dependency property
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- WPF中使用DataGridView创建报表控件
- 使用WPF来创建 Metro UI程序
- WPF显示经常使用的几个显示文字控件TextBox, TextBlock, Lable
- VS2010 使用GDI+创建显示GIF的MFC程序
- WPF-使用代码创建Grid行与列,并将控件添加到Grid中的指定行指定列
- VS2003 C#:重写键盘响应事件、动态创建控件、创建线程、在线程中使用委托在界面显示数据