Silverlight: the XAML ASP.NET control and embeded XAML

Even though the Xaml's XamlUrl porperty seems to indicate that it can only load XAML from an existing url, the truth is that you can also pass it a reference to a XAML excerpt which is embeded on the page. here's a quick example of how you can do this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <script type="text/xaml" id="xamlContent">
      <Canvas
        x:Name="parentCanvas"
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Width="640"
        Height="480"
        Background="Wheat">
        <TextBlock
          Canvas.Left="20"
          FontSize="24"
          Text="Hi"/>
      </Canvas>
    </script>

    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="manager" />
    <div>
        <asp:Xaml runat="server"
            Height="400"
            Width="600"
            XamlUrl="#xamlContent"
            ID="myXaml" ></asp:Xaml>
    </div>
    </form>
</body>
</html>

Filed under:

Comments

# Dave Reed said:

Have you tried this in Firefox? (hint: remove the DOCTYPE...)

Wednesday, July 25, 2007 5:34 PM
# luisabreu said:

honestly: no :) as always, you're right.

Wednesday, July 25, 2007 5:43 PM

Leave a Comment

(required) 
(required) 
(optional)
(required)