Silverlight: the XAML ASP.NET control and embeded XAML

Published Wed, Jul 25 2007 11:30

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 on Wednesday, July 25, 2007 5:34 PM

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

# luisabreu said on Wednesday, July 25, 2007 5:43 PM

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

Leave a Comment

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