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 5928809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:20:11+00:00 2026-05-22T14:20:11+00:00

I think I’m missing something fundamental in WPF data binding here: I have this

  • 0

I think I’m missing something fundamental in WPF data binding here:

I have this XML file:

<?xml version="1.0" encoding="utf-8" ?>
<WindowList>
  <Window Height="10" Width="10" ALL_MODEL_MODEL="xyz0" ALL_MODEL_MANUFACTURER="leidi"/>
  <Window Height="20" Width="20" ALL_MODEL_MODEL="xyz1" ALL_MODEL_MANUFACTURER="goffin"/>
  <Window Height="30" Width="30" ALL_MODEL_MODEL="xyz2" ALL_MODEL_MANUFACTURER="schlueter"/>
  <Window Height="40" Width="40" ALL_MODEL_MODEL="xyz3" ALL_MODEL_MANUFACTURER="rossi"/>
</WindowList>

And this XAML file:

<Window x:Class="BindListToXDocument.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <ListView Name="lstWindows">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Height" 
                     DisplayMemberBinding="{Binding Path=Attribute[Height].Value}"/>
                    <GridViewColumn Header="Width" 
                     DisplayMemberBinding="{Binding Path=Attribute[Width].Value}"/>
                    <GridViewColumn Header="Model" 
                     DisplayMemberBinding="{Binding Path=Attribute[Model].Value}"/>
                    <GridViewColumn Header="Manufacturer" 
                     DisplayMemberBinding="{Binding Path=Attribute[Manufacturer].Value}"/>
                </GridView>
            </ListView.View>
        </ListView>
        <Button Click="Button_Click">Populate List</Button>
    </StackPanel>
</Window>

The binding expressions are modeled after this Document on msdn: How to: Bind to XDocument, XElement, or LINQ for XML Query Results.

I then use the following code to set the DataContext:

private void Button_Click(object sender, RoutedEventArgs e)
{
    var doc = XDocument.Load("WindowList.xml");
    var windows = doc.Root.Elements();
    lstWindows.DataContext = windows;
}

The code runs without any complaints, when I click the button, but the list items never show up. I can’t figure out how to go about debugging this. Do you have any pointers for debugging binding expressions in general or how to bind the XDocument specifically?

EDIT: OK, it seems I was missing something crucial in my XAML:

<ListView Name="lstWindows" ItemsSource="{Binding}"> <!-- specify the ItemsSource! -->

I’ll leave this question here, since it is a minimal example of binding to an XDocument, something I was having trouble finding – most examples already went a step further. I’m still interested in tips for debugging, though.

  • 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-22T14:20:12+00:00Added an answer on May 22, 2026 at 2:20 pm

    I did these changes to populate the view…

    XAML: set the itemssource property of ListView

    <ListView Name="lstWindows" Height="400" ItemsSource="{Binding Path=Elements}">
    

    .CS file : create a property which returns IEnumerable

    public IEnumerable<XElement> Elements
    {
        get
            {
                var doc = XDocument.Load(@"\abc.xml");
                var windows = doc.Root.Elements();
                return windows;
            }
    }
    

    in load method of window… or you can also do this in button click event

    this.DataContext = this; or lstWindows.DataContext = this;

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

Sidebar

Related Questions

I think I'm missing something basic here. Any explanation or pointers to previously asked
I think I'm missing something basic here. Why is the third IF condition true?
Think of the following code: static int Main() { byte[] data = File.ReadAllBytes(anyfile); SomeMethod(data);
Think that I have many activities,and all I want is this: I have a
Think at this scenario: I have a c# windows form application. This application was
I think that I am misunderstanding something about how jquery $(this) works. In my
I think I got all the steps down but I must be missing something
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think the file that is produced is an .asm file, any idea how
I think most people know how to do this via the GUI (right click

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.