動態解析XAML文字構建WPF的UI

2022-03-21 23:51:01 字數 435 閱讀 7309

(1)手工拼湊字串

string strxaml = @"";

stringreader readerxaml = new stringreader(strxaml);

xmltextreader xtrxaml = new xmltextreader(readerxaml);

object objxaml = xamlreader.load(xtrxaml);

this.content = objxaml;          

注意:1.為了便於編輯,將""改為''

2.button元素必須指定命名空間,否則xamlreader無法辨識其型別,報錯

(2)讀取已有文件

注意:已有文件的buildaction必須設定為resource而不是page,否則xmltextreader 將其解析為十六進製制字串,而無法載入

wp8動態載入xaml控制項

一 字串形式載入xaml控制項 private void button clilk object sender,routedeventargs e 按下button clilk事件 載入乙個新的button控制項 btnred 二 路徑形式載入xaml控制項 private void btn cli...

WPF中動態新增xaml資源檔案

一 新建乙個資源檔案,然後設定其build actoin 生成操作 為resource 資源 resourcedictionary languageresdic new resourcedictionary languageresdic.source new uri dictionary1.xaml...

MessageFormat(動態文字)

messageformat 動態文字 如果乙個字串中包含了多個與國際化相關的資料,可以使用messageformat 類對這些資料進行批量處理 messageformat類如何驚醒批量處理呢?messageformat類允許開發人員用佔位符替換掉字串中的敏感資料 即國際化相關的資料 messagef...