سؤال

ما هو الحد الأدنى سبيل المثال حقا من تطبيق 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 #؟ ملف مصدر واحد وهو ما يمكن ترجمة من سطر الأوامر؟ إذا كان الأمر كذلك، ما من شأنه أن يكون رمز المصدر؟

وحافزي هو محاولة إنشاء التطبيق سلفرليغت مع لغات غير تقليدية، الآن أنا عالقة في بو ...

هل كانت مفيدة؟

المحلول

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 (واحدة من المكتبات بوو من انها دليل) وتسميته إلى hello.xap.

وأتش تي أم أل للنظر في ما يلي:

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top