惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
V
Visual Studio Blog
有赞技术团队
有赞技术团队
U
Unit 42
D
Docker
小众软件
小众软件
F
Full Disclosure
I
Intezer
Scott Helme
Scott Helme
P
Privacy International News Feed
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
B
Blog
Martin Fowler
Martin Fowler
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
宝玉的分享
宝玉的分享
S
Security Affairs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
Schneier on Security
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Threat Research - Cisco Blogs
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Heimdal Security Blog
N
Netflix TechBlog - Medium
H
Hacker News: Front Page
P
Proofpoint News Feed
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
S
Schneier on Security

博客园 - 挑战

从存储过程中读取相关信息 Blend Step by Step书籍笔记(第一章) WPF非轮询方式实时更新数据库变化SqlDependency 解决为'*********' 的游标已存在问题 数据表死锁查询和处理 SQL Server操作XML(六)XML FLOWR SQL Server操作XML(五)XML Query-XQuery SQL Server操作XML(四)XML数据类型 SQL Server操作XML(三)OPENXML函数功能 SQL Server操作XML(二)XML子句实例 SQL Server操作XML(一)XML子句 数据绑定 最为详尽的WPF类继承关系 LinQ数据访问 WPF Diagram Designer Part 3:连接Item 照猫画虎WPF之二数据绑定 照猫画虎WPF之一:命名空间 解决WPF部署后客户端访问安全性问题 C#读取文本播放相应语音
动态解析XAML文本构建WPF的UI
挑战 · 2012-07-07 · via 博客园 - 挑战

 (1)手工拼凑字符串

      string strXaml = @"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Content='Button' Height='23' Name='button1' Width='75' />";
      StringReader readerXaml = new StringReader(strXaml);
      XmlTextReader xtrXaml = new XmlTextReader(readerXaml);
      object objXaml = XamlReader.Load(xtrXaml);
      this.Content = objXaml;          

      注意:

      1.为了便于编辑,将""改为''

      2.Button元素必须指定命名空间,否则XamlReader无法辨识其类型,报错

 (2)读取已有文档

            string strXaml = "";
            Object dataObject = new Object();
            Uri uri = new Uri(@"/DepartmentElement.xaml", UriKind.Relative);
            StreamResourceInfo info = Application.GetResourceStream(uri);
            using (StreamReader sr = new StreamReader(info.Stream))
            {
                strXaml = sr.ReadToEnd();
            }
            StringReader readerXaml = new StringReader(strXaml);
            XmlTextReader xtrXaml = new XmlTextReader(readerXaml);
            object objXaml = XamlReader.Load(xtrXaml);
            this.Content = objXaml;

        注意:已有文档的BuildAction必须设置为Resource而不是Page,否则XmlTextReader 将其解析为十六进制字符串,而无法加载