Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:33:12+00:00 2026-06-17T05:33:12+00:00

An XML file should be opened and the elements should be displayed in a

  • 0

An XML file should be opened and the elements should be displayed in a ListBox where single elements can be selected. The selected elements should be displayed in a TextBox where they can be changed.

I managed to open and display the XML file in the ListBox. But how can I manage to display the selected XML content in the 2 TextBoxes?

Here is the content of the XML file.

<Inventory xmlns="">
    <Books>
        <Book ISBN="0-7356-0562-9" Stock="in" Number="9">
            <Title>XML in Action</Title>
            <Summary>XML Web Technology</Summary>
        </Book>
        <Book ISBN="0-7356-1370-2" Stock="in" Number="8">
            <Title>Programming Microsoft Windows With C#</Title>
            <Summary>C# Programming using the .NET Framework</Summary>
        </Book>
        <Book ISBN="0-7356-1288-9" Stock="out" Number="7">
            <Title>Inside C#</Title>
            <Summary>C# Language Programming</Summary>
        </Book>
        <Book ISBN="0-7356-1377-X" Stock="in" Number="5">
            <Title>Introducing Microsoft .NET</Title>
            <Summary>Overview of .NET Technology</Summary>
        </Book>
        <Book ISBN="0-7356-1448-2" Stock="out" Number="4">
            <Title>Microsoft C# Language Specifications</Title>
            <Summary>The C# language definition</Summary>
        </Book>
    </Books>
</Inventory>

And here is the content of MainWindow.xaml.

<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="XML_View_Edit.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"
    Width="500"
    Height="200">
    <Window.Resources>
        <XmlDataProvider x:Key="InventoryData"
                         XPath="Inventory/Books"
                         Source="Data.xml"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition
                Height="100" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <ListBox
            Grid.Row="0"
            Name="listBox1" >
            <ListBox.ItemsSource>
                <Binding Source="{StaticResource InventoryData}" XPath="Book"/>
            </ListBox.ItemsSource>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text = "{Binding XPath=Title}" />
                        <TextBlock Text= " - " />
                        <TextBlock Text = "{Binding XPath=Summary}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Grid
            Grid.Row="1"
             DataContext="listBox1.SelectedItem">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition
                    Width="70" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label
                Content="Title"
                Grid.Row="0"
                Grid.Column="0"
                Name="label_title" />
            <Label
                Content="Summary"
                Grid.Row="1"
                Grid.Column="0"
                Name="label_summary" />
            <TextBox
                Grid.Column="1"
                Name="textbox_title"
                Grid.Row="0" />
            <TextBox
                Grid.Column="1"
                Name="textbox_summary"
                Grid.Row="1" />
        </Grid>
    </Grid>
</Window>

The Title and Summary of the selected Book should be displayed in the 2 TextBoxes, where the user can change each value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:33:13+00:00Added an answer on June 17, 2026 at 5:33 am

    Roughly:

    • place the 2 TextBoxes on a Container C1
    • Bind C1.DataContext to ListBox1.SelectedItem

    And I’m not sure what results XPath="*" in the ListBox1 binding wil give. You probably want something like:

    <Binding Source="{StaticResource InventoryData}" XPath="@ISBN"/>
    

    Edit

    You need to actually bind the TextBox elements:

          <TextBox
                Grid.Column="1"
                Name="textbox_title"
                Text = "{Binding XPath=Title}"   <!-- this -->
                Grid.Row="0" />
            <TextBox
                Grid.Column="1"
                Name="textbox_summary"
                Text = "{Binding XPath=Summary}"   <!-- and this -->
                Grid.Row="1" />
    

    Give that a try.

    Edit 2:

    And let’s fix the binding of the inner Grid:

      DataContext="{Binding ElementName=listBox1, Path=SelectedItem}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to write an XML file using java.The contents should be written from
I have 5 different key/value pairs and I know how my xml file should
I am converting my XML file to CSV using XML2CSV The XML format can
I need to write a XML file which should conform to a schema. The
I should be able to loads the related XML file and displays the content
I am developing a webpart that should read an XML file. For this I
XML File Sample <GateDocument> <GateDocumentFeatures> ... </GateDocumentFeatures> <TextWithNodes> <Node id=0/> MESSAGE SET <Node id=19/>
my xml file has a tag with an attribute containsValue which contains the special
The XML file: <Lista count=3> <Pelicula nombre=Jurasic Park 3> <Genero>Drama</Genero> <Director sexo=M>Esteven Spielberg</Director> <Temporada>
my Xml file : <?xml version=1.0 encoding=utf-8?> <ArrayOfCustomer xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Customer> <CustomerId>1f323c97-2015-4a3d-9956-a93115c272ea</CustomerId> <FirstName>Aria</FirstName> <LastName>Stark</LastName>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.