문제
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
그런 다음 사용했습니다 키론 그리고 그것은 .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은 43KB이며 Ironpython 및 DLR로 얻은 1.5MB보다 훨씬 좋습니다.
제휴하지 않습니다 StackOverflow