Domanda

Qual è l'esempio davvero minimo dell'applicazione Silverlight?

Ad esempio, ho fatto il seguente esempio con 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

Quindi ho usato chirone e ho creato un file .xap. No (esplicito) XAML, niente di niente. È possibile fare lo stesso in, diciamo, in C #? Un file sorgente che potrei compilare dalla riga di comando? In tal caso, quale sarebbe il codice sorgente?

La mia motivazione è provare a creare un'app Silverlight con linguaggi non convenzionali, in questo momento sono bloccato su Boo ...

È stato utile?

Soluzione

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

Altri suggerimenti

Trovato un esempio F # qui .

Ha fatto un esempio di Boo basato su di esso. Il codice sorgente:

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

Costruito con:

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>

Quindi ha creato un normale file .zip contenente AppManifest.xaml, Hello.dll e Boo.Lang.dll (una delle librerie Boo dalla sua directory) e lo ha rinominato in hello.xap.

Un html per vederlo:

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

Il risultato hello.xap è 43 KB, che è molto meglio di 1,5 MB che ho ottenuto con IronPython e DLR.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top