Silverlight

From no name for this wiki
Jump to: navigation, search

Dokumentation

Calling Webservices

Interacting with the browser

DockPanel

DockPanel hats nicht ins Silverlight geschaft. Using Dock Panel in SL2 Anbei eine Toolkit Library: http://www.codeplex.com/Silverlight

Dynamischer Content

XAML kann on the fly heruntergeladen werden: dynamischer content

void SomeMethod()
{
 WebClient client = new WebClient();
  ...
 client.DownloadStringCompleted += 
   new DownloadStringCompletedEventHandler(OnDownloadCompleted);
 Uri uri = new Uri("xaml.ashx", UriKind.Relative);
 client.DownloadStringAsync(uri);
}

void OnDownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    // Parse XAML to a UI element 
    string xaml = e.Result;
    UIElement dom = XamlReader.Load(xaml) as UIElement;

    // Append to the DOM
    Placeholder.Children.Clear();
    Placeholder.Children.Add(dom);
}

Localization

  • 1. Projekt Datei mit <SupportedCultures>de;en</SupportedCultures> abändern. (Unload Project, xml anpassen, load project).
  • 2. Datei Res1.resx anlagen. Datei Res1.de.resx und Res1.en.resx anlegen (keine Unterverzeichnisse nötig).
  • 3. Designer erstellt eine generierte Hilfs-Klasse, um mit Keys auf Strings zuzuggreiffen.
  • 4. Klasse erstellen und in App.xml als statische Resource hinzufügen.
  • 5. Binding der Controls zur statischen Resource machen.
  • 6. Startup parameter:
<param name="uiculture" value="de" />
<param name="culture" value="de" />

Standalone hello World

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <title>Moonlight Stand-alone test page</title>
   </head>
      
   <body>      
      <object type="application/x-silverlight" data="data:," id="slControl" width="300" height="300">
         <param name="background" value="#CCCCCC"/>
         <param name="source"     value="#xamlContent"/>
      </object> 
      
      <!--  ADD YOUR XAML CONTENT HERE -->
      <script type="text/xaml" id="xamlContent">
      
         <?xml version="1.0"?>
         <Canvas Width="300" Height="300" xmlns="http://schemas.microsoft.com/client/2007"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="rootCanvas" >

            <TextBlock Canvas.Top="50" Canvas.Left="50">Standalone html/xaml file</TextBlock>

         </Canvas> 

      </script>
   </body>
</html>