Please Help import namespace

quddusaliquddus

Active member
Joined
Nov 20, 2007
Messages
25
Programming Experience
Beginner
I have the following code:

VB.NET:
Private Function ParseXAML(ByVal O As Object, ByVal XAML As String) As Object

    Dim newChild As ModelVisual3D
    Dim ThisXAML As String = XAML
    Dim X As XElement

    Try

        X = XElement.Load(New StringReader(ThisXAML))
        Dim thisXAMLReader As New XamlReader
        newChild = CType(XamlReader.Load(X.CreateReader), ModelVisual3D)
        O.Children.Add(newChild)

    Catch ex As Exception

        MessageBox.Show(ex.Message)
        Return Nothing

    End Try

End Function

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button5.Click
    Dim X As XElement = _
<ModelVisual3D
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    x:Name="World"
    >
    <ModelVisual3D x:Name="AmbientLightContainer">
        <ModelVisual3D.Content>
            <AmbientLight x:Name="AmbientLight" Color="#FF7F7F7F"/>
        </ModelVisual3D.Content>
    </ModelVisual3D>
    <ModelVisual3D x:Name="DirectionalLightContainer">
        <ModelVisual3D.Content>
            <DirectionalLight x:Name="DirectionalLight" Color="#FF3F3F3F" Direction="0,0,-1">
                <DirectionalLight.Transform>
                    <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="3"/>
                </DirectionalLight.Transform>
            </DirectionalLight>
        </ModelVisual3D.Content>
    </ModelVisual3D>
    <ModelVisual3D x:Name="DefaultGroup">
        <ModelVisual3D.Content>
            <GeometryModel3D x:Name="Suzanne" d:Bounds="-1.36718797683716,-0.851562976837158,-0.984375,2.73437595367432,1.70312595367432,1.96875">
                <GeometryModel3D.Geometry>
                    <MeshGeometry3D Positions="0.46875,0.75781298,-0.24218801 0.4375,0.765625,-0.16406301 503 491 364 491 381 493 504 367 493 367 384 379 381 491 379 491 410 493 384 380 493 380 412"/>
                </GeometryModel3D.Geometry>
                <GeometryModel3D.Material>
                    <DiffuseMaterial Brush="#FFFFFFFF"/>
                </GeometryModel3D.Material>
            </GeometryModel3D>
        </ModelVisual3D.Content>
        <ModelVisual3D.Transform>
            <Transform3DGroup>
                <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
                <ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
                <RotateTransform3D d:EulerAngles="0,0,0"/>
            </Transform3DGroup>
        </ModelVisual3D.Transform>
    </ModelVisual3D>
</ModelVisual3D>

    Dim XPath As String

    'XPath = "./ModelVisual3D/ModelVisual3D/ModelVisual3D.Transform/Transform3DGroup/TranslateTransform3D"

    XPath = "//Transform3DGroup/TranslateTransform3D"

    X.XPathSelectElement(XPath).SetAttributeValue("OffsetX", "5")

    'ParseXAML(V, X.ToString)

    'Console.WriteLine(X.ToString)

    Dim reader As XmlReader = X.CreateReader
    Dim nameTable As XmlNameTable = reader.NameTable
    Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nameTable)
    namespaceManager.AddNamespace("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation")
    Dim child1 As XElement = X.XPathSelectElement("//Transform3DGroup/TranslateTransform3D", namespaceManager)

    child1.SetAttributeValue("OffsetX", "1")

    namespaceManager.RemoveNamespace("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation")

    ParseXAML(V, X.ToString)

End Sub

And when I try to run it without this import at the beginning:

Imports <xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">


I get the folloiwng error:

The tag 'ModelVisual3D' does not exist in XML namespace ''. Line '0' Position '0'.


at:

newChild = CType(XamlReader.Load(X.CreateReader), ModelVisual3D)


And if I add the import then i get the following error:

Object reference not set to an instance of an object.

at:

X.XPathSelectElement(XPath).SetAttributeValue("OffsetX", "5")


Could someone help me resolve it please?

Many thanks


Q
 
Last edited by a moderator:

Latest posts

Back
Top