当前位置: 首页 > news >正文

WPF Frame 简单页面切换示例

原理比较简单,但是有个坑,为了使界面能够正确更新,记得使用 INotifyPropertyChanged 接口来实现属性更改通知。

<Window x:Class="PageTest.MainWindow"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:local="clr-namespace:PageTest"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><Grid.RowDefinitions><RowDefinition Height="0.1*"/><RowDefinition/></Grid.RowDefinitions><StackPanel Orientation="Horizontal"><Button Width="50" Height="25" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" Click="Button_Click"></Button><Button Width="50" Height="25" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" Click="Button_Click_1"></Button></StackPanel><Frame Grid.Row="1" Content="{Binding CurMain}" NavigationUIVisibility="Hidden"></Frame></Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;namespace PageTest
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>[AddINotifyPropertyChangedInterface]public partial class MainWindow : Window{public MainWindow(){InitializeComponent();DataContext = this;}object curMain;public object CurMain { get => curMain; set => curMain = value; }private void Button_Click(object sender, RoutedEventArgs e){CurMain = new Page1();}private void Button_Click_1(object sender, RoutedEventArgs e){CurMain = new Page2();}}
}
http://www.lryc.cn/news/370120.html

相关文章:

  • kafka-生产者监听器(SpringBoot整合Kafka)
  • 3D感知视觉表示与模型分析:深入探究视觉基础模型的三维意识
  • VS2019+QT5.15调用动态库dll带有命名空间
  • 助力草莓智能自动化采摘,基于YOLOv5全系列【n/s/m/l/x】参数模型开发构建果园种植采摘场景下草莓成熟度智能检测识别系统
  • C++中的生成器模式
  • 基于python的PDF文件解析器汇总
  • C++多线程同步总结
  • 【机器学习】基于CNN-RNN模型的验证码图片识别
  • 一文读懂Samtec分离式线缆组件选型 | 快速攻略
  • 批量申请SSL证书如何做到既方便成本又最低
  • Python 设计模式(创建型)
  • PyTorch 索引与切片-Tensor基本操作
  • 深入浅出 LangChain 与智能 Agent:构建下一代 AI 助手
  • scss是什么安装使⽤的步骤
  • Pspark从hive读数据写到Pgsql数据库
  • Pixi.js学习 (六)数组
  • 操作系统复习-Linux的文件系统
  • 代码随想录算法训练营第三十六天| 860.柠檬水找零、 406.根据身高重建队列、 452. 用最少数量的箭引爆气球
  • 如何在C#中实现多线程
  • 【LLM】快速了解Dify 0.6.10的核心功能:知识库检索、Agent创建和工作流编排(二)
  • 【介绍下Pandas,什么是Pandas?】
  • linux系统安装anaconda,并通过java程序调用python程序
  • Stable diffusion的SDXL模型,针不错!(含实操)
  • wordpress轻量免费主题
  • Go AfterFunc 不触发
  • 小程序视图渲染数据和部分事件的绑定
  • “探索AIGC市场:腾讯元宝APP加入竞争,大模型产品的未来走向与个人选择“
  • node设置镜像源详细教程
  • 四季变换,制氮机使用注意事项
  • 如何实现办公终端安全