Compiled XAML(BAML)にならない
WPFだとBAMLになる(id:kageroh_:20090515:1242317466)んだけど、SilverlightだとLoose XAMLのままなのはなんでなのかなあ…… XBAPはどうなんだろうか。と言うか、XAP(ただのzip archive。中身はAppManifest.xamlと*.dll)じゃなくて、BAMLにした、プログラムなしの、ただのCanvasを(X)HTMLに埋め込みたいだけなんだけど……
SilverlightCanvas.csproj
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <OutputType>Library</OutputType> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <XapOutputs>true</XapOutputs> <GenerateSilverlightManifest>true</GenerateSilverlightManifest> <XapFilename>SilverlightCanvas.xap</XapFilename> <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate> <SilverlightAppEntry>SilverlightCanvas.App</SilverlightAppEntry> <TestPageFileName>TestPage.html</TestPageFileName> <CreateTestPage>true</CreateTestPage> <Optimize>true</Optimize> <OutputPath>Bin\Release</OutputPath> </PropertyGroup> <ItemGroup> <Reference Include="System"/> <Reference Include="System.Core"/> <Reference Include="System.Windows"/> <Reference Include="System.Windows.Browser"/> <Compile Include="App.xaml.cs"/> <Compile Include="Page.xaml.cs"/> <ApplicationDefinition Include="App.xaml"/> <Page Include="Page.xaml"/> </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets"/> </Project>
Properties\AppManifest.xml
<?xml version="1.0" encoding="utf-8"?> <Deployment xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/client/2007/deployment"/>
App.xaml.cs
using System; using System.Windows; namespace SilverlightCanvas { public partial class App : Application { public App() { this.Startup += this.Application_Startup; this.Exit += this.Application_Exit; this.UnhandledException += this.Application_UnhandledException; InitializeComponent(); } private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new Page(); } private void Application_Exit(object sender, EventArgs e) {} private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (!System.Diagnostics.Debugger.IsAttached) { e.Handled = true; Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); } } private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e) { try { string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace; errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n"); System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");"); } catch (Exception) { } } } }
App.xaml
<?xml version="1.0" encoding="utf-8"?> <Application x:Class="SilverlightCanvas.App" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"/>
Page.xaml.cs
using System.Windows.Controls; namespace SilverlightCanvas { public partial class Page : UserControl { public Page() { InitializeComponent(); } } }
Page.xaml
<?xml version="1.0" encoding="utf-8"?> <UserControl x:Class="SilverlightCanvas.Page" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/client/2007"> <Canvas> <Ellipse Height="200" Width="200" Stroke="Black" StrokeThickness="10" Fill="SlateBlue"/> </Canvas> </UserControl>
MSBuild.bat
@echo off setlocal %windir%\Microsoft.NET\Framework\v3.5\MSBuild endlocal echo on