Now you need to use buttons to control the values displayed by Silverlight on the interface. The method is as follows.
1. First, compile a method that can be accessed by JS in usercontrol in Silverlight. Note: This method uses the scriptablemember feature.
// How to compile js to access Silverlight , SelectDate is the parameter
[Scriptablemember ()]
Public Void Gettrendchart ( String SelectDate)
{
Datetime tempdate = New Datetime ();
If ( String . Isnullorempty (SelectDate) | ! Datetime. tryparse (SelectDate, Out Tempdate ))
{
Showinfo ( " Incorrect date " );
Return ;
}
// Obtain information and change the Silverlight display value. The createtrendchart ()Code.
Createtrendchart (SelectDate);
}
2. Register this method in APP. XAML.
// Register in APP. XAML
Private Void Application_startup ( Object Sender, startupeventargs E)
{
// Call usercontrol
This . Rootvisual = New Trend ();
//How to register JS access
System. Windows. browser. htmlpage. registerscriptableobject ("Trendmethod",This
. Rootvisual );
}
3. Add an onload event to Silverlight on the aspx page.
<% -- Call siliverlight -- %>
< Object Data = "Data: Application/x-silverlight-2 ," Type = "Application/x-silverlight-2"
Width = "100%" Height = "100%" >
< Param Name = "Source" Value = "../Clientbin/iaddtech. Environmental. Web. Silverlight. xap" />
< Param Name = "Onerror" Value = "Onsilverlighterror" />
< Param Name = "Background" Value = "White" />
< Param Name = "Minruntimeversion" Value = "3.0.40818.0" />
<% -- Add a load event -- %>
param name =" onLoad " value =" silverloaded " />
< Param Name = "Autoupgrade" Value = "True" />
< Param Name = "Windowless" Value = "True" />
< A Href = "Http://go.microsoft.com/fwlink? Linkid = 149156 & V = 3.0.40818.0" Style = "Text-Decoration: none" >
< IMG SRC = "Http://go.microsoft.com/fwlink? Linkid = 108181" ALT = "Get Microsoft Silverlight"
Style = "Border-style: none" />
</ A >
</ Object >
4. Compile the onload event. Get the siliverlight object through the onload event.
< Script Type = "Text/JavaScript" >
VaR Silverlightobj = Null ;
Function Silverloaded (sender, argS ){
Silverlightobj
=
Sender. gethost (); // Get siliverlight object
}
</ Script >
5. Add an input on the ASPX page. Use this input to change the display value of Silverlight. The onclick method of this input is gettrenddata.
< Div Class = "Query_button" >
< Input Type = "Image" Value = "Getdate" Onclick = "Gettrenddata (); Return false ;" SRC = "../Resources/images/see_button.jpg" />
</ Div >
6. Add the input Click Event in Js. Call methods in Silverlight through the Click Event
< Script Type = "Text/JavaScript" >
// Input Click Event
Function Gettrenddata (){
//Silverlightobj has obtained, SelectDate is a parameter for Silverlight
Silverlightobj. content. trendmethod. gettrendchart (SelectDate );
}
</ Script >
In this way, you can use js to control the display value of Silverlight.