Why non-dynamic XML literals inherit the default namespace

I have an XElement that I need to create using dynamic XML literals / inline expressions, and I need it to inherit the default namespace. This is not possible, although through everything I tried. Does anyone know how to make this work?

for example

Imports <xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
Sub CreateXAML()
        Dim obj = "Rectangle"
        Dim objFill As String = obj & ".Fill"
        Dim myXML As XElement = <<%= obj %>><<%= objFill %>>no namespace</></>

        Dim myXML2 As XElement = <Path><Path.Fill>inherits namespace</Path.Fill></Path>
        MsgBox(myXML.ToString & vbCrLf & myXML2.ToString)
End Sub

The first myXML,, is not created with default ns, and the second,, myXML2is.

+5
source share
1 answer

http://msdn.microsoft.com/en-us/library/bb675177.aspx " ", , . , , , , :

Imports <xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
Sub CreateXAML()
    Dim shape = "Rectangle"
    Dim obj = <<%= "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}" & shape %>></>
    Dim objFill = <<%= "{http://schemas.microsoft.com/winfx/2006/xaml/presentation}" & shape %>></>
    Dim myXML As XElement = <<%= obj %>><<%= objFill %>>has namespace</></>

    Dim myXML2 As XElement = <Rectangle><Rectangle.Fill>inherits namespace</Rectangle.Fill></Rectangle>
    MsgBox(myXML.ToString & vbCrLf & myXML2.ToString)
End Sub

, "" . , XElement . :

<<%= obj %>><<%= objFill %>><Text>has namespace</Text></></>
+3

All Articles