0

我的网站使用silverlight 应用程序使用应用程序的xap 文件。是否可以捕获用户单击 silverlight 控件时发生的“onclick”事件?我想重新聚焦屏幕,以便在发生这种情况时只有控件可见。

我可以同时控制 silverlight 代码和网站代码,因此无论从哪个方向的解决方案都将受到同样的赞赏。

请注意,我对 Silverlight 非常陌生,所以如果上述任何一个听起来是“n00b-y”......好吧,确实如此。对不起 :)

4

1 回答 1

1

Find out your main XAML file of your Silverlight application by checking the RootVisual assignment statement in App.xaml.cs file.

private void Application_Startup(object sender, StartupEventArgs e)
{
    **this.RootVisual = new MainPage();**
}

By default, MainPage.xaml.cs is the first UserControl to be loaded on Application Startup.

Attach an event handler to the UserControl.MouseLeftButtonDown event in the MainPage constructor

public MainPage()
{
    InitializeComponent();
    **this.MouseLeftButtonDown += MainPage_MouseLeftButtonDown;**
}

In the event hander, invoke your javascript method "refocusScreen" (you need to implement this method the re-focus the screen) using Html Bridge

void MainPage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    // About [Invoke][2] method
    **HtmlPage.Document.Invoke("refocusScreen");**

    // detach event handler so that this won't call the JS method everytime the Mouse left button goes down.
    this.MouseLeftButtonDown -= MainPage_MouseLeftButtonDown;
}
于 2011-05-26T22:24:55.043 回答