题
什么是Silverlight应用程序的真正最小示例
例如,我的IronPython作了如下示例:
from System.Windows import Application
from System.Windows.Controls import Canvas, TextBlock
canvas = Canvas()
textblock = TextBlock()
textblock.FontSize = 24
textblock.Text = 'Hello!'
canvas.Children.Add(textblock)
Application.Current.RootVisual = canvas
然后我用的 Chiron公司并它创建了一个.xap文件。否(明确的)XAML,什么都没有。是否有可能做同样的,比方说,C#?一个源文件,我可以从命令行编译?如果是这样,将源代码是什么呢?
我的动机是试图创建一个非传统的语言的Silverlight应用程序,现在我停留在嘘......
解决方案
using System;
using System.Windows;
using System.Windows.Controls;
namespace MimimalSilverlightApp
{
public class App : Application
{
public App()
{
this.Startup += this.Application_Startup;
}
private void Application_Startup(object sender, StartupEventArgs e)
{
var canvas = new Canvas();
var textblock = new TextBlock();
textblock.FontSize = 24;
textblock.Text = "Hello!";
canvas.Children.Add(textblock);
this.RootVisual = canvas;
}
}
}
其他提示
实测值的F#示例此处。
由基于它嘘声例子。的源代码:
namespace Hello
import System
import System.Windows
import System.Windows.Controls
class MyPage(UserControl):
def constructor():
canvas = Canvas()
textblock = TextBlock()
textblock.FontSize = 24
textblock.Text = "Hello!"
canvas.Children.Add(textblock)
self.Content = canvas
class MyApp(Application):
def constructor():
Startup += onStartup
def onStartup(sender, e):
self.RootVisual = MyPage()
内置有:
booc -nostdlib -target:library -lib:"C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies","C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client" -r:System.Windows.dll -r:System.Windows.Controls.dll Hello.boo
在AppManifest.xaml:
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
EntryPointAssembly="Hello"
EntryPointType="Hello.MyApp" RuntimeVersion="2.0.31005.0">
<Deployment.Parts>
<AssemblyPart x:Name="Hello" Source="Hello.dll" />
<AssemblyPart x:Name="Boo.Lang" Source="Boo.Lang.dll" />
</Deployment.Parts>
</Deployment>
然后由含有AppManifest.xaml,Hello.dll的和Boo.Lang.dll(啵库从它的目录中的一个)的普通.zip文件并更名为hello.xap。
一个HTML来看待它:
<html>
<head></head>
<body>
<object id="SilverlightPlugin" data="data:application/x-silverlight,"
type="application/x-silverlight-2" width="450" height="540">
<param name="source" value="hello.xap"/>
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181"
alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
</body>
</html>
将所得hello.xap是43 KB,比1.5 MB,我与IronPython和DLR得到好得多。
不隶属于 StackOverflow