Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 你能取消一页的关闭吗_Silverlight_Google Chrome - Fatal编程技术网

Silverlight 你能取消一页的关闭吗

Silverlight 你能取消一页的关闭吗,silverlight,google-chrome,Silverlight,Google Chrome,根据我的Silverlight应用程序中的某些条件,是否有任何方法可以取消页面关闭?目的:在使用此应用程序时,我希望有一个部分保持打开状态,直到它们结束某项任务,然后浏览器可以正常响应。我只是不想发生任何意外的关门。如果这是不可能的,这是好的,我会解决它。该应用程序位于ASPX页面中 经过一些工作,这里是包装器(VB>NET) 公共类SWC 处理窗口关闭事件的“”事件参数。 公共类HtmlWindowCloseEventArgs:继承CancelEventArgs ''获取或设置要向用户显示的消

根据我的
Silverlight
应用程序中的某些条件,是否有任何方法可以取消页面关闭?目的:在使用此应用程序时,我希望有一个部分保持打开状态,直到它们结束某项任务,然后浏览器可以正常响应。我只是不想发生任何意外的关门。如果这是不可能的,这是好的,我会解决它。该应用程序位于
ASPX
页面中

经过一些工作,这里是包装器(VB>NET)

公共类SWC
处理窗口关闭事件的“”事件参数。
公共类HtmlWindowCloseEventArgs:继承CancelEventArgs
''获取或设置要向用户显示的消息,询问他们是否要继续关闭窗口。
公共属性DialogMessage()作为字符串
得到
返回对话框消息
结束
设置(值为字符串)
_dialogMessage=值
端集
端属性
私有对话框消息作为字符串
末级
''监视HTML窗口的关闭。
公共类HtmlWindowCloseMonitor
#区域“活动”
在紧靠车窗关闭之前,会触发“”。
公共共享事件窗口作为事件处理程序关闭(属于HtmlWindowCloseEventArgs)
私有共享子窗口关闭(发件人作为对象,e作为HtmlWindowCloseEventArgs)
RaiseEvent窗口关闭(发送器,e)
端接头
#末端区域
#区域“头”
Private Const ScriptableObjectName As String=“HtmlWindowCloseMonitor”
Private Const DefaultDialogMessage As String=“是否确实要关闭应用程序?”
私有共享只读实例作为HtmlWindowCloseMonitor
''构造函数。
共享子新()
如果实例什么都不是,那么
实例=新的HtmlWindowCloseMonitor()
如果结束
端接头
私人分新
'注册可编写脚本的回调成员。
RegisterScriptableObject(ScriptableObjectName,Me)
'检索插件的名称。
Dim pluginName=HtmlPage.Plugin.Id
如果pluginName什么都不是,那么
抛出新异常(“无法注册'onbeforeunload'事件,因为Silverlight没有ID。请向Silverlight主机标记添加ID属性。”)
如果结束
'连线事件。
Dim eventFunction=String.Format(“window.onbeforeunload=function(){{{}和Environment.NewLine&
“var slApp=document.getElementById('{0}');”&Environment.NewLine&
“var result=slApp.Content.{1}.OnBeforeUnload();”&Environment.NewLine&
“如果(结果!=null&&result.length>0)”&Environment.NewLine&
“return result;”&Environment.NewLine&“}}”,pluginName,ScriptableObjectName)
HtmlPage.Window.Eval(eventFunction)
端接头
#末端区域
#区域“方法”
_
作为字符串的公共函数OnBeforeUnload()
'与事件侦听器一起检查,以查看是否有任何侦听器想要取消窗口关闭操作。
Dim args=New HtmlWindowCloseEventArgs()
OnWindowClosing(Me、args)
如果不是args,则取消
“没有人想阻止窗户关上。
一无所获
如果结束
'向用户显示'Are you sure'对话框(通过浏览器)。
Dim message=If(args.DialogMessage不是空的,args.DialogMessage,DefaultDialogMessage)
回信
端函数
#末端区域
末级
末级

您可以绑定onBeforeUnload/BeforeUnload事件来询问用户。

HtmlPage.Window.AttacheEvent(“BeforeUnload”,HandleBeforeUnload);和声明public void HandleBeforeUnload(对象发送方,HtmlEventArgs){..}是否
beforeunload
事件与
ASPX
默认页面中的事件匹配?我没有看到这个名字的。请看:大约5分钟前才发现,我正在查看。我可以通过e.cancel看到我的代码运行,我的消息不是空的,没有对话框。我的Plugin.Id正在工作。我想知道javascript。我会把它贴在问题里。
Public Class SWC
 ''' <summary>Event arguments for handling the window close event.</summary>
  Public Class HtmlWindowCloseEventArgs : Inherits CancelEventArgs
   ''' <summary>Gets or sets the message to display to the user asking them if they want to continue the window close.</summary>
    Public Property DialogMessage() As String
      Get
        Return _dialogMessage
      End Get
      Set(value As String)
        _dialogMessage = value
      End Set
    End Property
    Private _dialogMessage As String
End Class
 ''' <summary>Monitors the closing of the HTML window.</summary>
 Public Class HtmlWindowCloseMonitor
#Region "Events"
    ''' <summary>Fires when immediately before the window closes.</summary>
    Public Shared Event WindowClosing As EventHandler(Of HtmlWindowCloseEventArgs)
    Private Shared Sub OnWindowClosing(sender As Object, e As HtmlWindowCloseEventArgs)
      RaiseEvent WindowClosing(sender, e)
    End Sub
#End Region
#Region "Head"
  Private Const ScriptableObjectName As String = "HtmlWindowCloseMonitor"
  Private Const DefaultDialogMessage As String = "Are you sure you want to close the application?"
  Private Shared ReadOnly instance As HtmlWindowCloseMonitor

    ''' <summary>Constructor.</summary>
    Shared Sub New()
      If instance Is Nothing Then
        instance = New HtmlWindowCloseMonitor()
      End If
    End Sub
    Private Sub New()
      ' Register the scriptable callback member.
      HtmlPage.RegisterScriptableObject(ScriptableObjectName, Me)

      ' Retrieve the name of the plugin.
      Dim pluginName = HtmlPage.Plugin.Id
      If pluginName Is Nothing Then
        Throw New Exception("Cannot register the 'onbeforeunload' event because the Silverlight <object> does not have an ID. Add an ID attribute to the Silverlight <object> host tag.")
      End If

      ' Wire up event.
      Dim eventFunction = String.Format("window.onbeforeunload = function () {{" & Environment.NewLine &
                                    "var slApp = document.getElementById('{0}');" & Environment.NewLine &
                                    "var result = slApp.Content.{1}.OnBeforeUnload();" & Environment.NewLine &
                                    "if(result != null && result.length > 0)" & Environment.NewLine &
                                    "return result;" & Environment.NewLine & "}}", pluginName, ScriptableObjectName)
      HtmlPage.Window.Eval(eventFunction)
    End Sub
#End Region
#Region "Methods"
   <ScriptableMember()> _
   Public Function OnBeforeUnload() As String
     ' Check with event-listeners to see if any of them want to cancel the window-close operation.
     Dim args = New HtmlWindowCloseEventArgs()
     OnWindowClosing(Me, args)
     If Not args.Cancel Then
      ' No one wanted to stop the window from closing.
      Return Nothing
     End If
     ' Present the 'Are you sure' dialog to the use (via the browser).
     Dim message = If(args.DialogMessage IsNot Nothing, args.DialogMessage, DefaultDialogMessage)
     Return message
   End Function
#End Region
End Class
End Class