Pregunta

¿Cuál es el ejemplo realmente mínimo de la aplicación Silverlight?

Por ejemplo, hice el siguiente ejemplo 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

Luego utilicé chiron y creó un archivo .xap. Sin XAML (explícito), sin nada. ¿Es posible hacer lo mismo en, digamos, C #? ¿Un archivo fuente que podría compilar desde la línea de comandos? Si es así, ¿cuál sería el código fuente?

Mi motivación es intentar crear una aplicación de Silverlight con lenguajes no convencionales, ahora estoy atrapado en Boo ...

¿Fue útil?

Solución

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

Otros consejos

Encontré un ejemplo de F # aquí .

Hizo un ejemplo de Boo basado en él. El código fuente:

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

Construido 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

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

Luego creó un archivo .zip ordinario que contiene AppManifest.xaml, Hello.dll y Boo.Lang.dll (una de las bibliotecas de Boo de su directorio) y lo renombró a hello.xap.

Un html para verlo:

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

El resultado hello.xap es de 43 KB, que es mucho mejor que 1.5 MB que obtuve con IronPython y DLR.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top