2009-01-17 11 views
1

Quel est l'exemple vraiment minimal de l'application Silverlight?Exemple Silverlight minimal

Par exemple, je fis l'exemple suivant avec 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 

J'utilisé chiron et il a créé un fichier .xap. Non (explicite) XAML, non rien. Est-il possible de faire la même chose, disons, C#? Un fichier source que je pourrais compiler à partir de la ligne de commande? Si oui, quel serait le code source?

Ma motivation est d'essayer de créer l'application silverlight avec les langues non conventionnelles, en ce moment je suis coincé à Boo ...

Répondre

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

un F # trouvé par exemple here.

Fait un exemple de Boo basé dessus. Le code source:

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

Construit avec:

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 

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

a ensuite fait un fichier .zip ordinaire contenant AppManifest.xaml, Hello.dll et Boo .Lang.dll (l'une des bibliothèques Boo de son répertoire) et renommé en hello.xap.

Un html de le regarder:

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

Le hello.xap résultant est 43 Ko, ce qui est beaucoup mieux que 1,5 Mo que j'ai eu avec IronPython et DLR.