添加关闭按钮

发布于 2024-07-29 00:09:11 字数 34 浏览 2 评论 0原文

如何在silverlight窗口的右上角添加关闭按钮?

How to add close button on the right top of the window in silverlight?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

°如果伤别离去 2024-08-05 00:09:11

假设:
1. 您需要使用 silverlight 中的控件来实现关闭功能。
2. 您希望关闭浏览器窗口。.

向 silverlight 控件添加按钮:

<Button Margin="0,10,10,0" x:Name="CloseButton" VerticalAlignment="Top" HorizontalAlignment="Right" Content="Close" Click="CloseButton_Click" Width="75" Height="22" />

添加 OnClick 事件:
如果您想关闭窗口,那么您将需要以一种或另一种方式执行一些 JavaScript。

解决方案 1:
您可以在 html/aspx 页面上添加一个 javascript 函数,例如:

<script type="text/javascript">
    function CloseWindow()
    {
        window.close();
    }
</script>

并调用它并添加 OnClick 事件:

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
    HtmlPage.Window.Invoke("CloseWindow");
}

解决方案 2:
或者,您可以使用 HtmlPageWindow.Eval() 方法执行“window.close()”,如下所示,无需在页面上使用 javascript 函数:

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
    HtmlPage.Window.Eval("window.close()");
}

Assumptions:
1. You are wanting a close function using a control from within silverlight.
2. You are wanting the browser window to be closed..

Adding a button to your silverlight control:

<Button Margin="0,10,10,0" x:Name="CloseButton" VerticalAlignment="Top" HorizontalAlignment="Right" Content="Close" Click="CloseButton_Click" Width="75" Height="22" />

Adding the OnClick event:
If you are wanting to close the window, then you will need to execute some javascript in one way or another.

Solution 1:
You can add a javascript function on your html/aspx page like:

<script type="text/javascript">
    function CloseWindow()
    {
        window.close();
    }
</script>

and call it adding the OnClick event:

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
    HtmlPage.Window.Invoke("CloseWindow");
}

Solution 2:
Alternatively you can execute the 'window.close()' using the HtmlPageWindow.Eval() method, like so without the need for a javascript function on the page:

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
    HtmlPage.Window.Eval("window.close()");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文