您的位置:首页 > 运维架构

稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件

2009-06-08 09:17 531 查看
[索引页]
[源码下载]

[align=center]稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件[/align]

作者:webabcd

介绍
Silverlight 2.0 提示和技巧系列

MessageBox - MessageBox 的演示
Popup - Popup 弹窗口的演示
循环的几种实现方法 - DispatcherTimer 方式, Storyboard 方式, Timer 方式, CompositionTarget.Rendering 方式
动态变换主题 - 演示如何动态地变换主题
本地化(多语言) - 演示如何实现对多语言的支持
响应鼠标双击事件 - 响应并处理鼠标的双击事件

在线DEMO
/article/4589581.html

示例
1、演示 MessageBox
MessageBoxDemo.xaml
<UserControl x:Class="Silverlight20.Tip.MessageBoxDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<Button x:Name="btnMessageBox" Content="MessageBox 演示" Click="btnMessageBox_Click" Margin="5" />
<TextBlock x:Name="lblResult" />
</StackPanel>
</Grid>
</UserControl>

MessageBoxDemo.xaml.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 Silverlight20.Tip

2、演示 Popup 弹出窗口
PopupDemo.xaml

<UserControl x:Class="Silverlight20.Tip.PopupDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="btnPopup" Content="弹出新窗口" Margin="5" Width="80" Height="40" Click="btnPopup_Click" HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>
</UserControl>

PopupDemo.xaml.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;

using System.Windows.Browser;

namespace Silverlight20.Tip

3、做循环程序的几种实现方法
LoopsDemo.xaml

<UserControl x:Class="Silverlight20.Tip.LoopsDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="DispatcherTimer: " />
<TextBlock x:Name="resultDispatcherTimer" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="Timer: " />
<TextBlock x:Name="resultTimer" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="StoryBoard: " />
<TextBlock x:Name="resultStoryBoard" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="CompositionTarget: " />
<TextBlock x:Name="resultCompositionTarget" />
</StackPanel>
</StackPanel>
</Grid>
</UserControl>

LoopsDemo.xaml.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;

using System.Windows.Threading;
using System.Threading;

namespace Silverlight20.Tip

4、动态变换主题(以 Toolkit 中的主题为例,引用 System.Windows.Controls.Theming.Toolkit.dll 和需要用到的相关主题文件)
ThemeDemo.xaml

<UserControl x:Class="Silverlight20.Tip.ThemeDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<Button Content="ExpressionDark 样式" Width="120" Height="40" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5" Click="Button_Click"></Button>
</Grid>
</UserControl>

<!--

在 xaml 文件中声明的方式使用主题

<UserControl x:Class="Silverlight20.Tip.ThemeDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myTheme="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.Toolkit">
<Grid x:Name="LayoutRoot" Background="White"
myTheme:ImplicitStyleManager.ApplyMode="Auto"
myTheme:ImplicitStyleManager.ResourceDictionaryUri="/Silverlight20;component/Theme/System.Windows.Controls.Theming.ExpressionDark.xaml"
>
<Button Content="ExpressionDark 样式" Width="120" Height="40" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5"></Button>
</Grid>
</UserControl>
-->
ThemeDemo.xaml.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;

using System.Windows.Controls.Theming;

namespace Silverlight20.Tip

5、演示如何实现本地化(多语言的支持)
LocalizationDemo.xaml

<UserControl x:Class="Silverlight20.Tip.LocalizationDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:Silverlight20.Resource">
<StackPanel Orientation="Vertical">

<StackPanel Margin="5">
<TextBlock Text="姓名: " />
<TextBlock x:Name="lblName" />
<TextBlock Text="年龄: " />
<TextBlock x:Name="lblAge" />
</StackPanel>

<!--通过声明的方式调用指定的本地化资源-->
<StackPanel.Resources>
<res:Localization x:Name="myRes" />
</StackPanel.Resources>
<StackPanel Margin="5">
<TextBlock Text="姓名: " />
<TextBlock Text="{Binding Name, Source={StaticResource myRes}}" />
<TextBlock Text="年龄: " />
<TextBlock Text="{Binding Age, Source={StaticResource myRes}}" />
</StackPanel>

</StackPanel>
</UserControl>

LocalizationDemo.xaml.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 Silverlight20.Tip
private void Application_Startup(object sender, StartupEventArgs e)
<!--演示如何在 Silverlight 中实现本地化-->
<!--通过为 object 标记设置如下参数来实现本地化(指定资源)-->
<param name="culture" value="en-US" />
<param name="uiculture" value="en-Us" />

6、响应并处理鼠标的双击事件
DoubleClick.xaml

<UserControl x:Class="Silverlight20.Tip.DoubleClick"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<Button x:Name="btn" Content="Double Click Me" Margin="5" Click="btn_Click" />
<TextBox x:Name="result" Margin="5" />
</StackPanel>
</Grid>
</UserControl>

DoubleClick.xaml.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;

using System.Windows.Threading;

namespace Silverlight20.Tip

OK
[源码下载]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐