I'm 开发者_开发知识库building an WPF (C#) application and I want to add a namespace to a XAML code (string type). I want to add the namespace on the correct place. Can anyone help me? Thanks, Peter.
EDIT:
It's a XAML code saved in a string like:
<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"....
I want to add a new namespace (like xmlns:test="http://www.test.nl") on the correct place.
As you have the XAML in one string, and presumably you have a second string containing the new namespace declaration, it seems that you simply need to use string.Insert to place it in. Your code would be as simple as this:
string xamlString = "... get some xaml from somewhere ...";
int insertPosition = xamlString.IndexOf(">");
xamlString.Insert(insertPosition, "my new namespace");
So I just get the index of the first closing angle bracket, and insert the new namespace right there.
精彩评论