WPF使用Page创建显示不同控件的程序
2011-11-22 14:16
423 查看
1. 测试环境
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的XAML文件
<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的XAML文件
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);
}
}
}
}
编译后,就可以看到效果拉!!!
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的XAML文件
<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的XAML文件
<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创建显示不同控件的程序
- MFC小程序003------MFC使用WebBrowser组件,在对话框中创建滚动视图,动态创建一个静态文本控件并设置鼠标单击的消息响应
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- 创建一个程序读入和显示视频文件,并可以使用滑动条控制视频文件的播放。一个滑动条用来控制视频播放位置,以10为步长跳进。另一个滑动条用来控制停止/播放
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- 在WPF程序中使用摄像头兼谈如何使用AForge.NET控件
- 同一程序在不同版本的framework下控件中英文显示的问题
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- 同一个窗口中不同的按钮控件使用同一个storyboard的方法(WPF)
- 包含别人的dll,然后我们用类库再次封装成dll的时候的注意事项;源文件与模块生成时的文件不同;创建调试信息文件 ··PDB时发生意外的错误,进程无法访问文件,因为另一个程序正在使用此文件
- 使用Caliburn.Micro创建简单的WPF程序
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- 使用WPF来创建 Metro UI程序
- Xceed WPF 3D显示控件Xceed 3D Views for WPF控件详细介绍使用及下载
- C++--如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- VS2010 使用GDI+创建显示GIF的MFC程序
- 使用服务提升程序的权限及不同用户切换时显示客户端程序的图标
- [WPF系列]-使用Binding来同步不同控件的Dependency property
- 如何实现SDI程序使用CSplitterWnd创建的多个视图的动态地显示和关闭视图
- VS2003 C#:重写键盘响应事件、动态创建控件、创建线程、在线程中使用委托在界面显示数据