Silverlight学习笔记(2)-安装Silverlight到本地
OutOfBrowser.xaml
<Button x:Name="button" Click="button_Click" Width=100 Height=30></Button>
OutOfBrowser.xaml.cs
public OutOfBrowser()
{
InitializeComponent();
this.Loaded+=new RoutedEventHandler(OutOfBrowser_Loaded);
}
void OutOfBrowser_Loaded(object sender,RoutedEventArgs e)
{
InitButton();
App.Current.InstallStateChanged+=new EventHandler(Current_InstallStateChanged);
}
void Current_InstallStateChanged(object sender,EventArgs e)
{
InitButton();
}
private void button_Click(object sender,RoutedEventArgs e)
{
if(!App.Current.IsRunningOutOfBrowser&& App.Current.InstallState==InstallState.NotInstalled)
App.Current.Install();
else
MessageBox.Show("请右键卸载!");
}
private void InitButton()
{
if(App.Current.IsRunningOutOfBrowser)
button.Content=”卸载”;
else
button.Content=”安装”;
}
右键单击解决方案中的Properties,选择打开,在打开的菜单中选择Silverlight,选中允许在浏览器外运行应用程序,然后单击浏览器外设置按钮,在打开的窗口中设置安装后要显示的窗口标题,高度和宽度,以及快捷名称和下载说明,设置完成后保存一下,会看到在Properties中生成了一个OutOfBrowserSettings.xml文件,文件中会显示刚才我们配置的一些信息。
然后运行就可以安装了!