zoukankan      html  css  js  c++  java
  • Silverlight中xaml之间的跳转方案之一

    1,先在Silverlight项目中新建一个接口文件IContent.cs,内容如下:

    using System.Windows;
    namespace BookStore 
    {
        public interface IContent 
        {
            UIElement Content
            { get; set; }
        }
    }
    

      2,建立两个xaml文件:Second.xaml和SilverlightControl1.xaml

    SilverlightControl1.xaml的完整内容如下:

    <UserControl x:Class="SilverlightApplication1.SilverlightControl1"
        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"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
        
        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0">
                <TextBlock Text="第一页"></TextBlock>
                <Button x:Name="BtnFirst" Content="First" Click="BtnFirst_Click"></Button>
            </StackPanel>
        </Grid>
    </UserControl>
    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;
    using BookStore;
    
    namespace SilverlightApplication1
    {
        public partial class SilverlightControl1 : UserControl,IContent
        {
            public SilverlightControl1()
            {
                InitializeComponent();
            }
    
            public new UIElement Content 
            {
                get { return base.Content; }
                set { base.Content = value; }
            }
    
            private void BtnFirst_Click(object sender,EventArgs e)
            {
                (Application.Current.RootVisual as IContent).Content = new Second();
            }
    
        }
    }

    Second.xaml完整内容如下:

    <UserControl x:Class="SilverlightApplication1.Second"
        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"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
        
        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.RowDefinitions>
                <RowDefinition Height="50"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="1">
                <TextBlock x:Name="TxtSecond" Text="Hello,Second!"></TextBlock>
                <Button x:Name="Btn_Second" Content="Second" Click="BtnSecond_Click"></Button>
            </StackPanel>
        </Grid>
    </UserControl>
    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;
    using BookStore;
    
    namespace SilverlightApplication1
    {
        public partial class Second : UserControl,IContent
        {
            public Second()
            {
                InitializeComponent();
            }
    
            public new UIElement Content 
            {
                get { return base.Content; }
                set { base.Content = value; }
            }
    
            private void BtnSecond_Click(object sender,EventArgs e)
            {
                (Application.Current.RootVisual as IContent).Content = new SilverlightControl1();
            }
        }
    }
  • 相关阅读:
    Jmeter系列(64)- JMeter JSR223 入门
    Jmeter系列(63)- Beanshell 入门
    Jmeter系列(62)- 详解 JSON 断言
    Jmeter系列(61)- 详解断言持续时间
    Jmeter系列(60)- 详解响应断言
    取球游戏|2012年蓝桥杯B组题解析第十题-fishers
    夺冠概率|2012年蓝桥杯B组题解析第九题-fishers
    密码发生器|2012年蓝桥杯B组题解析第八题-fishers
    放棋子|2012年蓝桥杯B组题解析第七题-fishers
    大数乘法|2012年蓝桥杯B组题解析第六题-fishers
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2745623.html
Copyright © 2011-2022 走看看