您的位置:首页 > 移动开发

稳扎稳打Silverlight(31) - 2.0Tip/Trick之加载XAP, 加载XAML, 加载DLL, AppManifest.xaml文件说明, 自定义鼠标指针

2009-06-01 09:09 621 查看
[索引页]
[源码下载]

[align=center]稳扎稳打Silverlight(31) - 2.0Tip/Trick之加载XAP, 加载XAML, 加载DLL, AppManifest.xaml文件说明, 自定义鼠标指针[/align]

作者:webabcd

介绍
Silverlight 2.0 提示和技巧系列

加载XAP - 加载指定的 xap 文件到当前的 Silverlight 应用程序中
加载XAML - 加载指定的 xaml 文件到当前的 Silverlight 应用程序中
加载DLL - 加载指定的 dll 文件,并调用其中的方法或加载其中的控件
AppManifest.xaml文件说明 - 简要说明 AppManifest.xaml 文件内容中各个节点的作用
自定义鼠标指针 - 实现自定义的鼠标指针,即鼠标跟随

在线DEMO
/article/4589581.html

示例
1、在 Silverlight 程序中加载指定的 xap 文件
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
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;

namespace Silverlight20.Tip

3、在 Silverlight 程序中加载指定的 dll 文件,并调用其中的方法或加载其中的控件
LoadDllDemo.Test.cs

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LoadDllDemo

LoadDll.xaml

<UserControl x:Class="Silverlight20.Tip.LoadDll"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">

<TextBlock x:Name="lblResult" Margin="5" />

</Grid>
</UserControl>

LoadDll.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.Reflection;

namespace Silverlight20.Tip

4、简要说明 AppManifest.xaml 文件内容中各个节点的作用

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="Silverlight20" EntryPointType="Silverlight20.App" RuntimeVersion="2.0.31005.0">
<Deployment.Parts>
<AssemblyPart x:Name="Silverlight20" Source="Silverlight20.dll" />
<AssemblyPart x:Name="Microsoft.Windows.Controls" Source="Microsoft.Windows.Controls.dll" />
</Deployment.Parts>
</Deployment>

一个 Silverlight 应用程序包(xap)内都会包含 AppManifest.xaml 文件,其内标识着打包的程序集和程序入口等信息

Deployment - 根节点
EntryPointAssembly - 程序入口的程序集
EntryPointType - 程序入口的类型
RuntimeVersion - 所需的 Silverlight 插件的版本
AssemblyPart - 标识 Silverlight 程序包(xap)内的程序集。其中的 Source 属性用于标识程序集的路径

5、自定义鼠标指针,即鼠标跟随
CustomMouseCursor.xaml

<UserControl x:Class="Silverlight20.Tip.CustomMouseCursor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="Bisque">
<Canvas x:Name="canvas">
<Ellipse x:Name="ellipse" Width="30" Height="30" Fill="Red" />
</Canvas>
</Grid>
</UserControl>

CustomMouseCursor.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;

namespace Silverlight20.Tip

OK
[源码下载]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐