稳扎稳打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
[源码下载]
[源码下载]
[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
[源码下载]
相关文章推荐
- 稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题
- 稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件
- 稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件
- 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件
- 稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键, 程序常用配置参数
- 动态改变DataWindow控件窗口中内容的几种实现方法
- 使用反射实现根据名称动态创建窗体的几种方法。
- 稳扎稳打Silverlight(29) - 2.0Tip/Trick之Cookie, 自定义字体, 为程序传递参数, 自定义鼠标右键
- 稳扎稳打Silverlight(30) - 2.0Tip/Trick之Silverlight.js, Silverlight.supportedUserAgent.js, 自定义启动界面, 响应鼠标滚轮事件
- silverlight中用代码动态控制Storyboard(动画)属性的几种方法
- Android viewpager中动态添加view并实现伪无限循环的方法
- 在Hibernate里面动态切换SChema实现访问不同的数据库的几种方法
- 实现Collection和Map接口的常用类的几种循环方法
- 动态改变DataWindow控件窗口中内容的几种实现方法
- jquery+css实现网页颜色主题变换(只改变已设置好的几种颜色主题)
- Silverlight 2.0使用Lock, Interlocked, EventWaitHandle, Monitor来实现线程同步//C#线程同步的几种方法
- 在Hibernate里面动态切换SChema实现访问不同的数据库的几种方法
- 使用反射实现根据名称动态创建窗体的几种方法。
- 稳扎稳打Silverlight(31) - 2.0Tip/Trick之加载XAP, 加载XAML, 加载DLL, AppManifest.xaml文件说明, 自定义鼠标指针
- 动态改变DataWindow控件窗口中内容的几种实现方法