大佬教程收集整理的这篇文章主要介绍了silverlight技巧 用xamlreader读写XAML页面.,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这次给大家晒晒 silverlight 用户控件的另一种写法xamlreader.
是不是有些朋友想过在 silverlighter 里使用 aps.net 里面的 response.write(); 方法输出HTML代码那样输出 XAML 代码呢? 呵呵这里我就给大家晒晒如何实现吧~
首先我要帮大家引入一个对象 他位置与 System.Windows.Markup; 命名空间下. 这里有一个静态类XamlReader,以及read方法 我们就要用他来创建我们的usercontrol.
- // SumMary:
- // Provides a XAML processor ENGIne @H_616_34@for parsing XAML and creaTing corresponding
- // Silverlight object trees.
- @H_616_34@public @H_616_34@static class XamlReader
- {
- // SumMary:
- // Parses a well-formed XAML fragment and creates a corresponding Silverlight
- // object tree, and @H_616_34@returns the root @H_616_34@of the object tree.
- //
- // Parameters:
- // xaml:
- // A String that @H_616_34@contains a valid XAML fragment.
- //
- // @H_616_34@Returns:
- // The root object @H_616_34@of the Silverlight object tree.
- @H_616_34@public @H_616_34@static object @H_616_34@Load(String xaml);
1. 我们创建一个类 自然就是我们的 usercontrol 了 继承自 control
2. 我们要把我们模板的 Xmal 以String 的形式保存写入程序中
3. 我们要在构造函数中载入这些 XAML
4. 我们在重载onapplytemplate() 方法中声明创建的对象XMAL代码.
以下是我要写入的Xaml;
- @H_616_34@public class MyImage : Control
- {
- Image _myImage = null;
- private const String _contentTemplate
- = "<ControlTemplate xmlns=\"http://scheR_594_11845@as.microsoft.com/winfx/2006/xaml/presentation\"" +
- "xmlns:x=\"http://scheR_594_11845@as.microsoft.com/winfx/2006/xaml\">" +
- "<Image x:Name=\"sonicImage\" source=\"space.jpg\"></Image>" +
- "</ControlTemplate>";
- }
构造函数
重载onapplytemplate
这样我们就可以更灵活的使用我们的用户控件,很简单吧~ 希望这点技巧对你有所帮助^^
source code: XamlReader_Demo
以上是大佬教程为你收集整理的silverlight技巧 用xamlreader读写XAML页面.全部内容,希望文章能够帮你解决silverlight技巧 用xamlreader读写XAML页面.所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。