My web site consumes a silverlight application using the application's xap file. Is it possible to catch the 'onclick' event that occurs when the use开发者_开发百科r clicks on the silverlight control? I would like to re-focus the screen so that only the control is visible when this happens.
I have control over both the silverlight code and the web site code, so a solution from either direction would be equally appreciated.
Please note that I am very new to Silverlight so if any of the above sounded 'n00b-y'... well, it was. Forgive me :)
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;
}
精彩评论