Load user control dynamically and default namespace

In Silverlight, when you want to create a control dynamically you have to add namespaces like this (as in http://msdn.microsoft.com/en-us/library/cc189044(VS.95).aspx ):

XNamespace xmlns = "http://schemas.microsoft.com/client/2007";
    XElement textBlock2 = new XElement(xmlns + "TextBlock",
        new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx/2006/xaml"),
        ...
        );

      

My problem is that I have a custom control in its own namespace, so I have to write something like

XNamespace myxmlns = "mynamespace";
XElement myelem = new XElement(myxmlns + "MyCtrl", ...

      

Then I can add aliased namespaces like

new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx")

      

but I can't figure out how to add the default namespace. I either get a compile error or a runtime error ("AG E PARSER MISSING DEFAULT NAMESPACE"), no matter what I try.

I managed to do this by building a big line of what I needed, but I would like to understand what is missing.

Any idea?

Thank.

+1


source to share


1 answer


From the XNamespace Documentation here :

new XAttribute("xmlns", "http://http://www.adventure-works.com")

      



Just add it as an XAttribute.

0


source







All Articles