I am supposed to bind data from an xml file to the textboxes but it is not worki
ID: 3823038 • Letter: I
Question
I am supposed to bind data from an xml file to the textboxes but it is not working. Could someone help me out?
I used this <TextBox x:Name="texBoxID" Grid.Column="1" Grid.Row="3" Margin="0,17,0,18" Text="{Binding XPath= ID}"/> but it did not work. What am I doing wrong?
Here is my XAML:
<Window x:Class="Assignment4._2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="1805">
<Window.Resources>
<XmlDataProvider x:Key="XDP" Source="Dialogfile.xml" XPath="Dialog"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="140" />
<ColumnDefinition Width="119"/>
<ColumnDefinition Width="140" />
<ColumnDefinition Width="101"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="140" />
<ColumnDefinition Width="119"/>
<ColumnDefinition Width="140" />
<ColumnDefinition Width="101"/>
<ColumnDefinition Width="130"/>
<ColumnDefinition Width="140" />
<ColumnDefinition Width="119"/>
<ColumnDefinition Width="140" />
<ColumnDefinition Width="101"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="65"/>
<RowDefinition Height="Auto" MinHeight="65"/>
<RowDefinition Height="60" MinHeight="20"/>
<RowDefinition Height="Auto" MinHeight="65"/>
<RowDefinition Height="Auto" MinHeight="65"/>
<RowDefinition Height="Auto" MinHeight="62"/>
<RowDefinition Height="Auto" MinHeight="68"/>
<RowDefinition Height="Auto" MinHeight="150"/>
<RowDefinition Height="Auto" MinHeight="54"/>
</Grid.RowDefinitions>
<Label x:Name="labelTarget" Content="TargetNPC" HorizontalAlignment="Center" Margin="38,0,20,0" Width="72" FontWeight="Bold"/>
<Label x:Name="labelCameraType" Content="Camera Type" Grid.Row="1" HorizontalAlignment="Center" Margin="28,25,22,24" Width="80" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Center" Padding="-2,5,5,5" Height="16"/>
<Label x:Name="labelID1" Content="ID:" Grid.Row="3" HorizontalAlignment="Center" Margin="30,0" Width="70" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label x:Name="labelType" Content="Type" Grid.Row="5" HorizontalAlignment="Center" Margin="16,0,28,0" Width="86" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Label x:Name="labelNode1" Content="Node 1:
" Grid.Row="2" HorizontalAlignment="Left" Margin="8,12,0,11" Width="102" FontWeight="Bold" VerticalAlignment="Center" Height="42"/>
<Label x:Name="labelSpeechType" Content="Speech Type:" Grid.Row="6" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center"/>
<Label x:Name="labelResponses" Content="Responses:" Grid.Row="7" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center"/>
<Label x:Name="labelNode1Question" Content="Text:" Grid.Row="4" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Label x:Name="labelNextNode" Content="Next Node:" Grid.Row="8" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<Label x:Name="labelInteraction" Content="Interaction" Grid.Column="2" Grid.Row="5" HorizontalAlignment="Center" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5"/>
<Label x:Name="labelQuest" Content="Quest" Grid.Column="2" Grid.Row="6" HorizontalAlignment="Center" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5"/>
<Label x:Name="labelStep" Content="Step" Grid.Column="2" Grid.Row="7" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5" VerticalAlignment="Top" Height="76"/>
<TextBox x:Name="textBoxNPC" Grid.Column="1" Margin="0,18,0,17"/>
<TextBox x:Name="textboxCamera" Grid.Column="1" Grid.Row="1" Margin="0,17,0,18"/>
<TextBox x:Name="texBoxID" Grid.Column="1" Grid.Row="3" Margin="0,17,0,18" Text="{Binding XPath= ID}"/>
<TextBox x:Name="textBoxResponse3" Grid.Column="1" Grid.Row="7" Margin="0,20" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="35"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxResponse1" Grid.Column="1" Grid.Row="7" Height="30" VerticalAlignment="Center" Padding="0,0,0,100" RenderTransformOrigin="0.5,0.5" Margin="0,24,0,28">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-35"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxResponse2" Grid.Column="1" Grid.Row="7" RenderTransformOrigin="0.5,0.5" Margin="0,20" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-2"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxText" Grid.Column="1" Grid.Row="4" Margin="0,18,0,17"/>
<TextBox x:Name="textBoxType" Grid.Column="1" Grid.Row="5" Margin="0,16"/>
<TextBox x:Name="textBoxSpeechType" Grid.Column="1" Grid.Row="6" Margin="0,19"/>
<TextBox x:Name="textBoxNN1" Grid.Column="1" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-20"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxNN2" Grid.Column="1" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="15"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxNN3" Grid.Column="1" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="50"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxInteraction" Grid.Column="3" Grid.Row="5" Margin="0,16"/>
<TextBox x:Name="textBoxQuest" Grid.Column="3" Grid.Row="6" Margin="0,19"/>
<TextBox x:Name="textBoxStep" Grid.Column="3" Grid.Row="7" Margin="0,19,0,98"/>
<Label x:Name="labelID2" Content="ID:" Grid.Column="5" Grid.Row="3" HorizontalAlignment="Center" Margin="30,0" Width="70" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label x:Name="labelType2" Content="Type" Grid.Column="5" Grid.Row="5" HorizontalAlignment="Center" Margin="16,0,28,0" Width="86" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Label x:Name="labelNode2" Content="Node 2:
" Grid.Column="5" Grid.Row="2" HorizontalAlignment="Left" Margin="8,12,0,11" Width="102" FontWeight="Bold" VerticalAlignment="Center" Height="42"/>
<Label x:Name="labelSpeechType2" Content="Speech Type:" Grid.Column="5" Grid.Row="6" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center"/>
<Label x:Name="labelResponses2" Content="Responses:" Grid.Column="5" Grid.Row="7" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center"/>
<Label x:Name="labelNode1Question2" Content="Text:" Grid.Column="5" Grid.Row="4" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Label x:Name="labelNextNode2" Content="Next Node:" Grid.Column="5" Grid.Row="8" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<Label x:Name="labelInteraction2" Content="Interaction" Grid.Column="7" Grid.Row="5" HorizontalAlignment="Center" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5"/>
<Label x:Name="labelQuest2" Content="Quest" Grid.Column="7" Grid.Row="6" HorizontalAlignment="Center" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5"/>
<Label x:Name="labelStep2" Content="Step" Grid.Column="7" Grid.Row="7" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5" VerticalAlignment="Top" Height="76"/>
<TextBox x:Name="texBoxID2" Grid.Column="6" Grid.Row="3" Margin="0,17,0,18"/>
<TextBox x:Name="textBox2Response3" Grid.Column="6" Grid.Row="7" Margin="0,20" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="35"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox2Response1" Grid.Column="6" Grid.Row="7" Height="30" VerticalAlignment="Center" Padding="0,0,0,100" RenderTransformOrigin="0.5,0.5" Margin="0,24,0,28">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-35"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox2Response2" Grid.Column="6" Grid.Row="7" RenderTransformOrigin="0.5,0.5" Margin="0,20" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-2"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxText2" Grid.Column="6" Grid.Row="4" Margin="0,18,0,17"/>
<TextBox x:Name="textBoxType2" Grid.Column="6" Grid.Row="5" Margin="0,16"/>
<TextBox x:Name="textBoxSpeechType2" Grid.Column="6" Grid.Row="6" Margin="0,19"/>
<TextBox x:Name="textBox2NN1" Grid.Column="6" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-20"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox2NN2" Grid.Column="6" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="15"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox2NN3" Grid.Column="6" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="50"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxInteraction2" Grid.Column="8" Grid.Row="5" Margin="0,16"/>
<TextBox x:Name="textBoxQuest2" Grid.Column="8" Grid.Row="6" Margin="0,19"/>
<TextBox x:Name="textBoxStep2" Grid.Column="8" Grid.Row="7" Margin="0,19,0,98"/>
<Label x:Name="labelID3" Content="ID:" Grid.Column="10" Grid.Row="3" HorizontalAlignment="Center" Margin="30,0" Width="70" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label x:Name="labelType3" Content="Type" Grid.Column="10" Grid.Row="5" HorizontalAlignment="Center" Margin="16,0,28,0" Width="86" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Label x:Name="labelNode3" Content="Node 3:
" Grid.Column="10" Grid.Row="2" HorizontalAlignment="Left" Margin="8,12,0,11" Width="102" FontWeight="Bold" VerticalAlignment="Center" Height="42"/>
<Label x:Name="labelSpeechType3" Content="Speech Type:" Grid.Column="10" Grid.Row="6" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center"/>
<Label x:Name="labelResponses3" Content="Responses:" Grid.Column="10" Grid.Row="7" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center"/>
<Label x:Name="labelNode1Question3" Content="Text:" Grid.Column="10" Grid.Row="4" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>
<Label x:Name="labelNextNode3" Content="Next Node:" Grid.Column="10" Grid.Row="8" HorizontalAlignment="Center" Margin="18,0,30,0" Width="82" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<Label x:Name="labelInteraction3" Content="Interaction" Grid.Column="12" Grid.Row="5" HorizontalAlignment="Center" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5"/>
<Label x:Name="labelQuest3" Content="Quest" Grid.Column="12" Grid.Row="6" HorizontalAlignment="Center" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5"/>
<Label x:Name="labelStep3" Content="Step" Grid.Column="12" Grid.Row="7" Margin="10,0" Width="99" FontWeight="Bold" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="5,5,-10,5" VerticalAlignment="Top" Height="76"/>
<TextBox x:Name="texBoxID3" Grid.Column="11" Grid.Row="3" Margin="0,17,0,18"/>
<TextBox x:Name="textBox3Response3" Grid.Column="11" Grid.Row="7" Margin="0,20" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="35"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox3Response1" Grid.Column="11" Grid.Row="7" Height="30" VerticalAlignment="Center" Padding="0,0,0,100" RenderTransformOrigin="0.5,0.5" Margin="0,24,0,28">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-35"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox3Response2" Grid.Column="11" Grid.Row="7" RenderTransformOrigin="0.5,0.5" Margin="0,20" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-2"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxText3" Grid.Column="11" Grid.Row="4" Margin="0,18,0,17"/>
<TextBox x:Name="textBoxType3" Grid.Column="11" Grid.Row="5" Margin="0,16"/>
<TextBox x:Name="textBoxSpeechType3" Grid.Column="11" Grid.Row="6" Margin="0,19"/>
<TextBox x:Name="textBox3NN1" Grid.Column="11" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="-20"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox3NN2" Grid.Column="11" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="15"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBox3NN3" Grid.Column="11" Grid.Row="8" Margin="0,18" RenderTransformOrigin="0.5,0.5" Height="30">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform Y="50"/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
<TextBox x:Name="textBoxInteraction3" Grid.Column="13" Grid.Row="5" Margin="0,16"/>
<TextBox x:Name="textBoxQuest3" Grid.Column="13" Grid.Row="6" Margin="0,19"/>
<TextBox x:Name="textBoxStep3" Grid.Column="13" Grid.Row="7" Margin="0,19,0,98"/>
</Grid>
</Window>
Here is the xml file:
<?xml version="1.0" encoding="utf-8" ?>
<Dialog>
<TargetNPC>NPC_11234</TargetNPC>
<CameraType>Automatic</CameraType> <!--[None, Automatic, Manual]-->
<Nodes>
<Node>
<ID>N_1</ID>
<Text>Would you like to go on a quest?</Text>
<Type>Speech</Type> <!--[Speech, Quest]-->
<SpeechType>Default</SpeechType><!--[Default, Yell, Narrative, Combat_Callout, Voiced_Player_Emote, Zone_Wide]-->
<Responses>
<Response>
<Text>Sure</Text>
<NextNode>N_2</NextNode>
</Response>
<Response>
<Text>No Thanks</Text>
<NextNode/>
</Response>
<Response>
<Text>Tell me more</Text>
<NextNode>N_3</NextNode>
</Response>
</Responses>
</Node>
<Node>
<ID>N_2</ID>
<Type>Quest</Type>
<InteractionType>Offer</InteractionType><!--[Offer, Advance, Complete, Fail]-->
<Quest>QU_0</Quest>
<Step>QS_0</Step>
<NextNode />
</Node>
<Node>
<ID>N_3</ID>
<Text>It really is a very nice quest, what do you say?</Text>
<Type>Speech</Type>
<SpeechType>Default</SpeechType>
<Responses>
<Response>
<Text>Sure</Text>
<NextNode>N_2</NextNode>
</Response>
<Response>
<Text>No Thanks</Text>
<NextNode/>
</Response>
<Response>
<Text>Still need more information, what will you give me?</Text>
<NextNode>N_4</NextNode>
</Response>
</Responses>
</Node>
<Node>
<ID>N_4</ID>
<Text>Some gold maybe?</Text>
<Type>Speech</Type>
<SpeechType>Default</SpeechType>
<Responses>
<Response>
<Text>Sure</Text>
<NextNode>N_2</NextNode>
</Response>
<Response>
<Text>No Thanks</Text>
<NextNode/>
</Response>
</Responses>
</Node>
</Nodes>
</Dialog>
Explanation / Answer
Seemed to be you given the code perfect... But missing thing is declare name to the XmlDataProvider tag.
<XmlDataProvider x:Name = "XDP" x:Key="XDP" Source="Dialogfile.xml" XPath="Dialog"/>
This Name should given and then it will work fine.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.