最小的 Silverlight 示例

发布于 2024-07-11 07:18:01 字数 540 浏览 8 评论 0原文

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 应用程序,现在我陷入了 Boo...

What is the really minimal example of Silverlight application?

For example, I made the following example with 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

Then I used chiron and it created a .xap file. No (explicit) XAML, no nothing. Is it possible to do the same in, say, C#? One source file which I could compile from command line? If so, what would the source code be?

My motivation is to try and create silverlight app with unconventional languages, right now I am stuck at Boo...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福%小乖 2024-07-18 07:18:01
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;
        }
    }
}
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;
        }
    }
}
初相遇 2024-07-18 07:18:01

此处找到了 F# 示例。

基于它做了一个Boo例子。 源代码:

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>

然后制作一个普通的 .zip 文件,其中包含 AppManifest.xaml、Hello.dll 和 Boo.Lang.dll(其目录中的 Boo 库之一),并将其重命名为 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,这比我使用 IronPython 和 DLR 获得的 1.5 MB 要好得多。

Found an F# example here.

Made a Boo example based on it. The source code:

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()

Built with:

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

The 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>

Then made an ordinary .zip file containing AppManifest.xaml, Hello.dll and Boo.Lang.dll (one of Boo libraries from it's directory) and renamed it into hello.xap.

An html to look at it:

<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>

The resulting hello.xap is 43 KB, which is much better than 1.5 MB that I got with IronPython and DLR.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文