zoukankan      html  css  js  c++  java
  • SilverLight动态加载控件<转>

     

    使用SilverLight动态加载控件XamlReader.Load的使用

    1.生明一个StringBuilder用于连接字符串
    2.创建命名空间(以及相应属性);
    2.创建控件使用XamlReader.Load
    3.加载到面板上面

    代码
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Net;
     5 using System.Windows;
     6 using System.Windows.Controls;
     7 using System.Windows.Documents;
     8 using System.Windows.Input;
     9 using System.Windows.Media;
    10 using System.Windows.Media.Animation;
    11 using System.Windows.Shapes;
    12 using System.Text;
    13 using System.Windows.Markup;
    14 namespace sl19
    15 {
    16     public partial class MainPage : UserControl
    17     {
    18         public MainPage()
    19         {
    20             InitializeComponent();
    21             ////textBlock里面的文本
    22             StringBuilder xaml = new StringBuilder();
    23             xaml.Append("<TextBlock ");
    24             xaml.Append("xmlns=\"http://schemas.microsoft.com/client/2007\" ");
    25             xaml.Append("Canvas.Left=\"50\" Canvas.Top=\"30\"  FontSize=\"50\" ");
    26             xaml.Append(" FontWeight=\"Bold\" Text=\"动态创建XAML对象\" />");
    27             //创建textBlock
    28             TextBlock textBlock = (TextBlock)XamlReader.Load(xaml.ToString());
    29             parentCanvas.Children.Add(textBlock);
    30             //line的xaml文本
    31            xaml= new StringBuilder();
    32             xaml.Append("<Line Stroke=\"Red\" ");
    33             xaml.Append("xmlns=\"http://schemas.microsoft.com/client/2007\" ");
    34             xaml.Append(" X1=\"30\" Y1=\"30\" ");
    35             xaml.Append(" X2=\"200\" Y2=\"200\"  StrokeThickness=\"3\" />");
    36             //创建LINE对象
    37             Line line = (Line)XamlReader.Load(xaml.ToString());
    38             parentCanvas.Children.Add(line);                       
    39         }
    40     }
    41 }
    42 

    总结:很简单的案例,但是自己按人家写出来发现也有点困难。

    原文地址:http://www.cnblogs.com/muer/archive/2010/05/18/1738486.html

    版权说明

      如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
      作      者:温景良
      文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

  • 相关阅读:
    sessionId在fragment里无法保存的问题
    android:ellipsize实现跑马灯效果总结(转)
    Android:TextView 自动滚动(跑马灯) (转)
    Failed to install on device ‘emulator-5554′: timeout
    一个类怎样引用另外一个类的成员变量或方法
    android.widget.RadioButton 单选按钮(转)
    如何实现两个Activity 之间如何通讯
    linux自学(八)之开始centos学习,安装tomcat
    linux自学(六)之开始centos学习,更换yum源
    linux自学(四)之开始centos学习,网络配置
  • 原文地址:https://www.cnblogs.com/wenjl520/p/1738698.html
Copyright © 2011-2022 走看看