日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

silverlight中如何方便在多个场景即Xaml文件之间随意切换?

發(fā)布時間:2023/12/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 silverlight中如何方便在多个场景即Xaml文件之间随意切换? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

注:以下方法是百度上搜索得來的,整理一下轉(zhuǎn)發(fā)于此

步驟1.先在silverlight項目中新建一個接口文件IContent.cs,內(nèi)容如下(namespace請各位根據(jù)自己的實際情況修改):

Code
using?System.Windows;

namespace?BookStore
{
????
public?interface?IContent
????{
????????UIElement?Content?{?
get;?set;?}
????}
}

?

步驟2.建二個Xaml文件Test.xaml和Test2.Xaml

Test.Xaml完整內(nèi)容如下:

Code
<UserControl?x:Class="BookStore.Test"
????xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"?
????xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"?
????Width
="600"?Height="400">
????
<Grid?x:Name="LayoutRoot"?Background="White"?>
????????
<StackPanel?Orientation="Vertical"?HorizontalAlignment="Center"?Margin="50"?Background="AliceBlue"?Width="200"?Height="100">
????????????
<TextBlock?TextAlignment="Center">
????????????????這是Test.Xaml文件
????????????
</TextBlock>
????????????
<Button?Height="25"?Width="150"?Content="轉(zhuǎn)到Test2.xaml"?Click="Button_Click"></Button>
????????
</StackPanel>
???????
????
</Grid>
</UserControl>

?

Test.Xaml.Cs完整內(nèi)容如下:

Code
using?System.Windows;
using?System.Windows.Controls;

namespace?BookStore
{

????
//手動增加,?IContent?,讓Test實現(xiàn)IContent接口
????public?partial?class?Test?:?UserControl,?IContent?
????{
????????
public?Test()
????????{
????????????InitializeComponent();
????????}

????????
private?void?Button_Click(object?sender,?RoutedEventArgs?e)
????????{
????????????
//實現(xiàn)切換(點擊test.xaml上的按鈕將切換到Test2"場景")
????????????(Application.Current.RootVisual?as?IContent).Content?=?new?Test2();???????????????????????
????????}


????????
///?<summary>
????????
///?增加一個Content屬性
????????
///?</summary>
????????public?new?UIElement?Content
????????{
????????????
get
????????????{
????????????????
return?base.Content;
????????????}
????????????
set
????????????{
????????????????
base.Content?=?value;
????????????}
????????}?

????}
}

?

Test2.Xaml完整內(nèi)容如下:

Code
<UserControl?x:Class="BookStore.Test2"
????xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"?
????xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"?
????Width
="600"?Height="400">
????
<Grid?x:Name="LayoutRoot"?Background="White"?>
????????
<StackPanel?Orientation="Vertical"?HorizontalAlignment="Center"?Margin="50"?Background="Beige"??Width="200"?Height="100">
????????????
<TextBlock?TextAlignment="Center">
????????????????這是Test2.Xaml文件
????????????
</TextBlock>
????????????
<Button?Height="25"?Width="150"?Content="轉(zhuǎn)到Test.xaml"?Click="Button_Click"></Button>
????????
</StackPanel>

????
</Grid>
</UserControl>

?

Test2.Xaml.cs完整內(nèi)容如下:(其實跟Test.Xaml.cs幾乎一樣)

Code
using?System.Windows;
using?System.Windows.Controls;

namespace?BookStore
{
????
//手動增加,?IContent?,讓Test2實現(xiàn)IContent接口
????public?partial?class?Test2?:?UserControl,?IContent
????{
????????
public?Test2()
????????{
????????????InitializeComponent();
????????}

????????
private?void?Button_Click(object?sender,?RoutedEventArgs?e)
????????{
????????
//就這一行有點一不樣(點擊test2.xaml上的按鈕將還回到Test"場景")
????????????(Application.Current.RootVisual?as?IContent).Content?=?new?Test();????????????
????????}

????????
///?<summary>
????????
///?增加一個Content屬性
????????
///?</summary>
????????public?new?UIElement?Content
????????{
????????????
get
????????????{
????????????????
return?base.Content;
????????????}
????????????
set
????????????{
????????????????
base.Content?=?value;
????????????}
????????}?
????}
}

?

運行效果圖如下:


歡迎轉(zhuǎn)載,但請注明來自"菩提樹下的楊過"

轉(zhuǎn)載于:https://www.cnblogs.com/yjmyzz/archive/2009/02/06/1385189.html

總結(jié)

以上是生活随笔為你收集整理的silverlight中如何方便在多个场景即Xaml文件之间随意切换?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。