asp.net中wpf實現page跳轉頁面

來源:互聯網
上載者:User

在wpf項目中,經常遇到需要跳轉視窗的功能,在以前分享一篇了

今天在分享一段代碼,是通過content進行頁面跳轉的,這個和web的跳轉就一點都不一樣了。

介面:

點擊menu1 和2都會跳轉到Page1.xaml和 Page2.xaml


前台xaml:

 代碼如下 複製代碼

<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Width="150" HorizontalAlignment="Left">
            <TextBlock FontSize="24" TextWrapping="Wrap">
        <Hyperlink x:Name="LnkPre" Foreground="Black" Click="LnkPre_Click">
            Menu1
        </Hyperlink>
            
        </TextBlock>
        <TextBlock FontSize="24" TextWrapping="Wrap">
        <Hyperlink x:Name="LnkPre1" Foreground="Black" Click="LnkPre1_Click">
            Menu2
        </Hyperlink>
        </TextBlock>
        </StackPanel>
        <Frame Name="pc" Width="340" HorizontalAlignment="Right">
        </Frame>
    </Grid>
</Window>

後台代碼跳轉:

 代碼如下 複製代碼

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
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    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;
        }
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.