2011-04-20 46 views
0

我正在構建一個WPF(C#)應用程序,並且我想向XAML代碼(字符串類型)添加一個名稱空間。我想在正確的位置添加名稱空間。誰能幫我?謝謝,彼得。將命名空間添加到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:測試=「HTTP://www.test .nl「)在正確的地方。

+0

什麼是「正確的地方」?) – Bick 2011-04-20 11:50:59

+0

在其他名稱空間下。但是XAML文檔並不總是相同的。 – Peter 2011-04-20 11:56:17

回答

3

當你有一個字符串的XAML,想必你有一個包含了新的命名空間聲明中的第二個字符串,看來你只需要使用string.Insert把它放在你的代碼是如此簡單:

string xamlString = "... get some xaml from somewhere ..."; 
int insertPosition = xamlString.IndexOf(">"); 
xamlString.Insert(insertPosition, "my new namespace"); 

因此,我只是得到第一個閉角尖括號的索引,並在那裏插入新的名稱空間。