none
silverlight 3中如何实现两个xaml之间的切换 RRS feed

答案


  • 你需要在恰当的地方放置一个页面容器,然后将需要切换的页面加入到容器中,就形成了页面切换的效果。

    Sample Code:
    1)MainPage.xaml
    <UserControl x:Class="AppSwitch.MainPage"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="20"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0"
                        Orientation="Horizontal">
                <TextBlock Text="This Is Main Page"></TextBlock>
                <Button x:Name="BtnSwitchToPageFirst"
                        Content="Switch To Page First"
                        Click="BtnSwitchToPageFirst_Click"></Button>
                <Button x:Name="BtnSwitchToPageSecond"
                        Content="Switch To Page Second"
                        Click="BtnSwitchToPageSecond_Click"></Button>
            </StackPanel>
            <Grid x:Name="GrdSubPageContainer"
                  Grid.Row="1">
            </Grid>
        </Grid>
    </UserControl>

    2)MainPage.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    namespace AppSwitch {
        public partial class MainPage : UserControl {
            public MainPage() {
                InitializeComponent();
            }
            private void BtnSwitchToPageFirst_Click(object sender, RoutedEventArgs e) {
                this.GrdSubPageContainer.Children.Clear();
                this.GrdSubPageContainer.Children.Add(new PageFirst());
            }

            private void BtnSwitchToPageSecond_Click(object sender, RoutedEventArgs e) {
                this.GrdSubPageContainer.Children.Clear();
                this.GrdSubPageContainer.Children.Add(new PageSecond());
            }
        }
    }

    2009年12月2日 2:36

全部回复

  • 切换啥?自己先看toolkit 写的例子。

    2009年12月2日 2:30
  • 先一个登陆的log.xaml,然后进入main.xmal

    2009年12月2日 2:33

  • 你需要在恰当的地方放置一个页面容器,然后将需要切换的页面加入到容器中,就形成了页面切换的效果。

    Sample Code:
    1)MainPage.xaml
    <UserControl x:Class="AppSwitch.MainPage"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="20"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0"
                        Orientation="Horizontal">
                <TextBlock Text="This Is Main Page"></TextBlock>
                <Button x:Name="BtnSwitchToPageFirst"
                        Content="Switch To Page First"
                        Click="BtnSwitchToPageFirst_Click"></Button>
                <Button x:Name="BtnSwitchToPageSecond"
                        Content="Switch To Page Second"
                        Click="BtnSwitchToPageSecond_Click"></Button>
            </StackPanel>
            <Grid x:Name="GrdSubPageContainer"
                  Grid.Row="1">
            </Grid>
        </Grid>
    </UserControl>

    2)MainPage.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    namespace AppSwitch {
        public partial class MainPage : UserControl {
            public MainPage() {
                InitializeComponent();
            }
            private void BtnSwitchToPageFirst_Click(object sender, RoutedEventArgs e) {
                this.GrdSubPageContainer.Children.Clear();
                this.GrdSubPageContainer.Children.Add(new PageFirst());
            }

            private void BtnSwitchToPageSecond_Click(object sender, RoutedEventArgs e) {
                this.GrdSubPageContainer.Children.Clear();
                this.GrdSubPageContainer.Children.Add(new PageSecond());
            }
        }
    }

    2009年12月2日 2:36