0

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.

1
  • Under other namespaces. But the XAML document is not always the same. Commented Apr 20, 2011 at 11:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.