Welcome

首页 / 软件开发 / Silverlight / 快速浏览Silverlight3:在浏览器外运行Silverlight应用

快速浏览Silverlight3:在浏览器外运行Silverlight应用2010-05-10 博客园 代震军翻译:http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/03/18/a-quick-look-at-silverlight-3-running-outside-the-browser.aspx

Silverlight3一个很显著的特点就是其应用可以在浏览器外运行。就是说一个在浏览器中运行的应用可以被独立(detached)出来,并通过一个桌面和开始菜单栏图标来启动执行,而不在需要有网络连接。这样给人的感觉其就像一个普通的桌面应用而不是一个浏览器应用程序。

为了实现独立(detached),用户必须对这类应用有个明确的选择:“该应用在没有用户通知的情况下是不可以detached它自己的。下面用一个例子“Hello World”来展示一下:

<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml%22
Width="400" Height="300">
<StackPanel x:Name="LayoutRoot" Background="White">
<TextBlock
x:Name="txtStatus" Text="Not Set" HorizontalAlignment="Center" Margin="10" />
<Button
Content="Click Me"
Click="OnClicked"
Margin="10"/>
</StackPanel>
</UserControl>

还有一些代码:

public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
OnExecutionStateChanged(null, null);
App.Current.ExecutionStateChanged += OnExecutionStateChanged;
}
void OnExecutionStateChanged(object sender, EventArgs e)
{
txtStatus.Text = App.Current.ExecutionState.ToString();
}
void OnClicked(object sender, RoutedEventArgs args)
{
App.Current.Detach();
}
}