Is there a way to insert Silverlight XAML into my page using ASP.NET code-behind?

后端 未结 4 1854
眼角桃花
眼角桃花 2021-01-03 19:08

So, I want to create some Silverlight charts from some data on my ASP.NET web page. The way to do this, either using Visifire (my current thing) or the upcoming Silverlight

4条回答
  •  感动是毒
    2021-01-03 19:20

    I'd suggest a more AJAXy sort of approach: have JS request the XAML and then runtime insert that XAML into the control (see the HTML Bridge) after the XAML has been returned from the server. That way your control could do a nice animation/transition to the new display.

    Still, you can do what you're aiming at:

    • Slap a Silverlight server control into your Update Panel.
    • Write an aspx page to generate the XAML (Change the DocType to make things easier)
    • Point the Silverlight server control at the .ASPX page:

      ... asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/myXAMLPage.aspx" MinimumVersion="2.0.30523" Width="100%" Height="100%">

    • Trigger the UpdatePanel to do it's thing whenever a user clicks your button.

    Now, whenever a user clicks a button, the Update Panel (containing the Silverlight control) will be rendered, and that SL control will request the XAML file and render what it finds.

    Do note, this approach instantiates the control with a XAML file. This means that you won't be able to use managed code in Silverlight. If you need managed code, instead of specifying the "myXAMLPage.aspx" page in the Source, specify your .xap file and then use an initparam to specify "myXAMLPage.aspx". Inside you're Silverlight application, download the xaml file (WebClient or whatever), and then use XamlReader.Load to load it up and display it.

    hth, Erik

提交回复
热议问题