WPF頁面切換及彈窗

來源:互聯網
上載者:User

標籤:

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 PageChange17 {18     /// <summary>19     /// MainWindow.xaml 的互動邏輯20     /// </summary>21     public partial class MainWindow : Window22     {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 }

 

WPF頁面切換及彈窗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.