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

  • Home
  • SEARCH
  • 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 7411893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:27:24+00:00 2026-05-29T06:27:24+00:00

i have some data saved in a xml file. Those will be displayed in

  • 0

i have some data saved in a xml file.
Those will be displayed in a listbox.
Now, when i change the listbox Selectedindex, i would like to update the other information in the textblock based on the selectedindex.

is there any way to do this in pure xaml?
if not, how would i bind the Textblock to the selecteditem in the listbox ?

EDIT:
How would i navigate through the Data without using the listbox? i mean using a button to move to next item and other button to move backward..!!

any help is really appreciated..

<Window x:Class="WpfSingleInstance.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
    <StackPanel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Cornsilk">

        <StackPanel.Resources>
            <XmlDataProvider x:Key="InventoryData" XPath="Inventory/Books">
                <x:XData>
                    <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>
                        </Books>
                    </Inventory>
                </x:XData>
            </XmlDataProvider>
        </StackPanel.Resources>

        <TextBlock FontSize="18" FontWeight="Bold" Margin="10"
HorizontalAlignment="Center">XML Data Source Sample</TextBlock>
        <ListBox
Width="265" Height="98" x:Name="lbox" Background="Honeydew" IsSynchronizedWithCurrentItem="True">
            <ListBox.ItemsSource>
                <Binding Source="{StaticResource InventoryData}"
           XPath="*[@Stock='out'] | *[@Number>=8 or @Number=3]"/>
            </ListBox.ItemsSource>

            <ListBox.ItemTemplate>

                <DataTemplate>
                    <TextBlock FontSize="12" Foreground="Red">
      <TextBlock.Text>
        <Binding XPath="Title"/>
      </TextBlock.Text>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <StackPanel DataContext="{StaticResource InventoryData}">
            <TextBlock Text="{Binding  XPath=Book/Title}"/>
            <TextBox Margin="5,31,98,10" x:Name="textBoxMainDetail" Text="{Binding XPath=Book/Summary}" />
        </StackPanel>
    </StackPanel>



</Grid>

  • 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-05-29T06:27:25+00:00Added an answer on May 29, 2026 at 6:27 am

    You could bind like this:

    <TextBox Text="{Binding ElementName=lbox, Path=SelectedItem[Title].InnerText}" />
    

    SelectedItem is an XmlElement.

    EDIT: Here is a bit of sample code how to access the data of the XmlDataProvider in code behind and apply it as DataContent of a TextBox.

    Change the TextBox.Text binding like this:

    <TextBox x:Name="textBoxMainDetail" Text="{Binding Path=[Title].InnerText}" />
    

    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];
    

    Note that the StackPanel with the XmlDataProvider in its resource dictionary has now got a name. If this code shall run during application initialization (e.g. in Window constructor), the XmlDataProvider.IsAsynchronous property must be set to false.

    You should now be able to change the DataContext to another indexed item of the books collection in a button click handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that I export into an XML file and put in
I am new to xml and visual c++.Now i have to save some data
I have two tabitems. User will enter some data and save it on the
I have some data. I want to go through that data and change cells
Imagine you have a library for working with some sort of XML file or
I have a .NET winform application that writes an XML data file, but I
How can I get some data from the tag of a xml file? I
I have some reference data in a text file (~5MB) that I want to
I have three buttons and need to save some data. I have a idea,
We have the requirement to take a form submission and save some data, then

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.