XML in Action
ID: 3536030 • Letter: X
Question
I am trying to figure out how to use the Xmldataprovider to be able to use information from a xml to two-way bind the information into a listbox that, when a company name is selected, its information will be displayed in textboxes (ex company name, phone contact ect.) I need to be able to have the ability to update the data in those textboxes which will then be saved. I have the xaml code finished, which is as follows:
<Window x:Class="FinalProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="631" Width="902">
<Canvas>
<Label Canvas.Left="100" Canvas.Top="93">Select Customer:</Label>
<TextBlock FontSize="30" Margin="20" Background="Blue" Foreground="White" Padding="10,0" Canvas.Left="301" Canvas.Top="-8">
My Final Project
</TextBlock>
<ListBox HorizontalAlignment="Right" Canvas.Left="364" Canvas.Top="79" Height="83" Width="343">
</ListBox>
<RadioButton Canvas.Left="100" Canvas.Top="177">
Sort Customer By Ascending Order
</RadioButton>
<RadioButton Canvas.Left="432" Canvas.Top="177">
Sort Customer By Descending Order
</RadioButton>
<TabPanel></TabPanel>
<TabControl Canvas.Left="100" Canvas.Top="214" Height="338" Width="642">
<TabItem Header="Customer Details" Background="White"></TabItem>
</TabControl>
<Canvas Height="297" Width="635" Canvas.Left="107" Canvas.Top="255">
<Label Canvas.Left="6" Canvas.Top="10">Company Name</Label>
<Label Canvas.Left="6" Canvas.Top="45">Contact Name</Label>
<Label Canvas.Left="6" Canvas.Top="80">Address</Label>
<Label Canvas.Left="6" Canvas.Top="115">City</Label>
<Label Canvas.Left="6" Canvas.Top="150">Country</Label>
<Label Canvas.Left="6" Canvas.Top="185">Zip</Label>
<Label Canvas.Left="6" Canvas.Top="215">Phone</Label>
<TextBox Canvas.Left="136" Canvas.Top="14" Width="427"/>
<TextBox Canvas.Left="136" Canvas.Top="47" Width="427" />
<TextBox Canvas.Left="136" Canvas.Top="84" Width="427" />
<TextBox Canvas.Left="136" Canvas.Top="119" Width="427" />
<TextBox Canvas.Left="136" Canvas.Top="154" Width="427" />
<TextBox Canvas.Left="136" Canvas.Top="189" Width="427" />
<TextBox Canvas.Left="136" Canvas.Top="219" Width="427" />
<Button Click="Button_Click" Canvas.Left="244" Canvas.Top="250" Width="193">Update</Button>
</Canvas>
</Canvas>
</Window>
Explanation / Answer
YOU CAN DO SOMETHING LIKE THIS..... XML in Action XML Web Technology Programming Microsoft Windows With C# C# Programming using the .NET Framework Inside C# C# Language Programming XML Data Source Sample In code behind get the XML data from the XmlDataProvider and set the DataContext of the TextBox:XmlDataProvider dataProvider = (XmlDataProvider)stackPanel.Resources["InventoryData"]; XmlElement books = (XmlElement)dataProvider.Document.SelectNodes(dataProvider.XPath)[0]; // set DataContext to an item from the child node collection textBoxMainDetail.DataContext = books.ChildNodes[0];Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.