洪星的博客(原创版,新闻除外)

信息技术 软件开发 电信 移动通信(欢迎和我交流:QQ219402,15152399197)

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
MainPage.xaml
<UserControl x:Class="Hongcing.SilverlightApplication.MainPage"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Loaded="LayoutRoot_Loaded" />
</UserControl>

 

MainPage.xaml.cs
1 using System.Windows;
2  using System.Windows.Controls;
3  using System.Windows.Markup;
4
5  namespace Hongcing.SilverlightApplication
6 {
7 public partial class MainPage : UserControl
8 {
9 public MainPage()
10 {
11 InitializeComponent();
12 }
13
14 private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
15 {
16 Panel panel = sender as Panel;
17
18 //注意:
19 //XAML 内容字符串必须定义单个根元素;必须是格式良好的 XML,并且必须是有效的 XAML。
20 //根元素必须指定某一默认的 XML 命名空间。
21 //通常是 Silverlight 命名空间 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"。
22 string xaml = "<TextBlock xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>Hello World!</TextBlock>";
23 UIElement element = XamlReader.Load(xaml) as UIElement;
24 panel.Children.Add(element);
25 }
26 }
27 }
28

 

 在 Microsoft Visual Studio 2008 SP1 和 Silverlight 3 Tools 环境下编译通过。

posted on 2010-02-01 21:50  洪星  阅读(1109)  评论(0编辑  收藏  举报