[英]Add namespace to XAML code
我正在構建WPF(C#)應用程序,並且想向XAML代碼(字符串類型)添加名稱空間。 我想在正確的位置添加名稱空間。 誰能幫我? 謝謝,彼得。
編輯:
這是一個保存在字符串中的XAML代碼,例如:
<UserControl x:Class="MyTestApp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"....
我想在正確的位置添加一個新的名稱空間(例如xmlns:test =“ http://www.test.nl”)。
當您在一個字符串中包含XAML時,並且大概在第二個字符串中包含新的名稱空間聲明,看來您只需要使用string.Insert即可將其放入其中。您的代碼將像這樣簡單:
string xamlString = "... get some xaml from somewhere ...";
int insertPosition = xamlString.IndexOf(">");
xamlString.Insert(insertPosition, "my new namespace");
因此,我只獲取第一個閉合尖括號的索引,然后在此處插入新的名稱空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.