Browser close from Silverlight

摘要:Browser close from Silverlight

MainPage.xaml

<UserControl x:Class=”TIPS.MainPage”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml
    xmlns:d=”http://schemas.microsoft.com/expression/blend/2008
    xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006
    mc:Ignorable=”d” d:DesignWidth=”640″ d:DesignHeight=”480″ xmlns:ctrl=”clr-namespace:TIPS”>
    <Grid Background=”Beige”>
        <Button x:Name=”btn” Click=”btn_Click” Width=”100″ Height=”30″ Content=”Close browser” />
    </Grid>
</UserControl>

MainPage.xaml.cs

using System.Windows.Browser;
using System.Windows.Controls;

namespace TIPS
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
        private void btn_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            HtmlPage.Window.Invoke(“close”);
        }
    }
}