asp.net中wpf实现page跳转页面

作者:袖梨 2022-06-25

在wpf项目中,经常遇到需要跳转窗口的功能,在以前分享一篇了

今天在分享一段代码,是通过content进行页面跳转的,这个和web的跳转就一点都不一样了。

界面:

IT分享wpf教程-page跳转页面

点击menu1 和2都会跳转到Page1.xaml和 Page2.xaml

IT分享wpf教程-page跳转页面
前台xaml:

代码如下 复制代码

xmlns="http://schemas.*micros*o*ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.*mi*croso*ft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">




Menu1





Menu2






后台代码跳转:

代码如下 复制代码

using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
{
///


/// MainWindow.xaml 的交互逻辑
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
pc.NavigationUIVisibility = NavigationUIVisibility.Hidden;
}
private void LnkPre1_Click(object sender, RoutedEventArgs e)
{
Page2 p2 = new Page2();
pc.Content = p2;
}
private void LnkPre_Click(object sender, RoutedEventArgs e)
{
Page1 p1 = new Page1();
pc.Content = p1;
}
}
}

相关文章

精彩推荐