Slow and steady Silverlight (31)

Source: Internet
Author: User
Tags relative resource xmlns silverlight

Steady Silverlight-2.0tip/trick load xap, load XAML, load Dll,appmanifest.xaml file description, customize mouse pointer

Introduced

Silverlight 2.0 Tips and Tricks series

Load XAP-Loads the specified XAP file into the current Silverlight application

Load XAML-loads the specified XAML file into the current Silverlight application

Load DLL-loads the specified DLL file, invokes the method in it, or loads the control in it

AppManifest.xaml File Description-Brief description of the role of each node in the AppManifest.xaml file content

Custom mouse pointer-implements a custom mouse pointer, that is, the mouse follows

Online Demo

Http://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.html

Example

1. Load the specified XAP file in the Silverlight program

Loadxap.xaml

<UserControl x:Class="Silverlight20.Tip.LoadXap"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<Button x:Name="load" Content="加载游戏 - 俄罗斯方块" Click="load_Click" Margin="5" />
<Grid x:Name="container" Margin="5" />
</StackPanel>
</Grid>
</UserControl>

LoadXap.xaml.cs

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Net;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Documents;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Animation;
Using System.Windows.Shapes;

Using System.Windows.Resources;
Using System.IO;
Using System.Xml.Linq;
Using System.Reflection;

Namespace Silverlight20.tip
{
public partial class Loadxap:usercontrol
{
Public Loadxap ()
{
InitializeComponent ();
}

private void Load_click (object sender, RoutedEventArgs e)
{
Uri uri = new Uri ("Yytetris.xap", urikind.relative);

Download the specified XAP with WebClient
WebClient client = new WebClient ();
Client. openreadcompleted + = new Openreadcompletedeventhandler (client_openreadcompleted);
Client. OpenReadAsync (URI);
}

void Client_openreadcompleted (object sender, Openreadcompletedeventargs e)
{
/**//*
* StreamResourceInfo-provides support for retrieving resources through the Silverlight application model
* Assemblypart-assemblies contained within the Silverlight program
* Assemblypart.load ()-loads the specified assembly into the current application domain
* Application.getresourcestream ()-Automatic decompression of zip-type files
*/

YYTETRIS.XAP's AppManifest.xaml information is as follows
/**//*
<deployment xmlns= "http://schemas.microsoft.com/client/2007/deployment" xmlns:x= "http://schemas.microsoft.com /winfx/2006/xaml "entrypointassembly=" Yytetris "entrypointtype=" Yytetris.app "runtimeversion=" 2.0.31005.0 ">
<Deployment.Parts>
<assemblypart x:name= "Yytetris" source= "YYTetris.dll"/>
</Deployment.Parts>
</Deployment>
*/

Obtains all Assemblypart node information within deployment.parts in the AppManifest.xaml of XAP
StreamResourceInfo resource = App.getresourcestream (
New StreamResourceInfo (E.result, NULL),
New Uri ("AppManifest.xaml", urikind.relative));
String resourcemanifest = new StreamReader (resource. Stream). ReadToEnd ();
list<xelement> assemblyparts = Xdocument.parse (resourcemanifest). Root.elements (). Elements (). ToList ();

Assembly Assembly = null;

foreach (xelement element in Assemblyparts)
{
Remove the DLL specified by the Assemblypart Source
String Source = element. Attribute ("Source"). Value;
Assemblypart Assemblypart = new Assemblypart ();
StreamResourceInfo Streaminfo = App.getresourcestream (
New StreamResourceInfo (E.result, "application/binary"),
New Uri (source, urikind.relative));

if (Source = = "YYTetris.dll")
Assembly = Assemblypart.load (Streaminfo.stream);
Else
Assemblypart.load (Streaminfo.stream);
}

Instantiating a yytetris.xap main function
var type = assembly. GetType ("Yytetris.page");
var Yytetris = activator.createinstance (type) as UIElement;

Add YYTETRIS.XAP to the specified container and update the UI
Container. Children.add (Yytetris);
Container. Updatelayout ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.