WPF页面切换及弹窗

WPF页面切换及弹窗

结构如图:

效果如图:

代码如下:

xaml

 1 <Window x:Class="PageChange.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         Title="MainWindow" Height="350" Width="400">
 5     <Grid>
 6         <Grid.ColumnDefinitions>
 7             <ColumnDefinition Width="100"></ColumnDefinition>
 8             <ColumnDefinition Width="300"></ColumnDefinition>
 9         </Grid.ColumnDefinitions>
10         <StackPanel Orientation="Vertical" Grid.Column="0">
11             <Button Content="第一页" Name="tb1" Click="tb1_Click"></Button>
12             <Button Content="第二页" Name="tb2" Click="tb2_Click"></Button>
13             <Button Content="第三页" Name="tb3" Click="tb3_Click"></Button>
14             <Button Content="弹窗" Name="tb4" Click="tb4_Click"></Button>
15         </StackPanel>
16         <Grid Grid.Column="1" Name="MyGrid" Height="300" Width="300"></Grid>
17        
18     </Grid>
19 </Window>

后置代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Windows;
 7 using System.Windows.Controls;
 8 using System.Windows.Data;
 9 using System.Windows.Documents;
10 using System.Windows.Input;
11 using System.Windows.Media;
12 using System.Windows.Media.Imaging;
13 using System.Windows.Navigation;
14 using System.Windows.Shapes;
15 
16 namespace PageChange
17 {
18     /// <summary>
19     /// MainWindow.xaml 的交互逻辑
20     /// </summary>
21     public partial class MainWindow : Window
22     {
23         public MainWindow()
24         {
25             InitializeComponent();
26         }
27 
28         private void tb1_Click(object sender, RoutedEventArgs e)
29         {
30             MyGrid.Children.Add(new Page1());
31         }
32 
33         private void tb2_Click(object sender, RoutedEventArgs e)
34         {
35             MyGrid.Children.Add(new Page2());
36         }
37 
38         private void tb3_Click(object sender, RoutedEventArgs e)
39         {
40             MyGrid.Children.Add(new Page3());
41         }
42 
43         private void tb4_Click(object sender, RoutedEventArgs e)
44         {
45             Window w = new Window();
46             NewPage n = new NewPage();
47             w.Content = n;
48             w.ShowDialog();
49         }
50     }
51 }

 

转载于:https://www.cnblogs.com/weiweiboqi/p/4673630.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值