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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:47:25+00:00 2026-06-07T17:47:25+00:00

Hi I have a listbox binded to a xml file, and each item I

  • 0

Hi I have a listbox binded to a xml file, and each item I gave them a button data template so I can easily register a click event to each item.

I would love to get the clicked button’s content to do some query on.

Here is my code

XAML

<ListBox  Name="listBox1" >
        <ListBox.ItemsSource>
            <Binding Source="{StaticResource keywordLib}" XPath="Position/Keyword/Word"/>
        </ListBox.ItemsSource>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Button Content="{Binding}" Click="keyword_Click"/>
            </DataTemplate>
        </ListBox.ItemTemplate>

    </ListBox>

After hours of googling for solutions. I know I should use sender from the click event, and that worked fine for a normal button, didn’t word here.

    private void keyword_Click(Object sender, RoutedEventArgs e)
    { 
       Button btn = (Button)sender;
       String keyword = btn.Content.ToString();
       MessageBox.Show(keyword);
     }

The messagebox showed “System.Xml.XmlElement”. Instead of the button content.

Many thanks to anyone could help me out on this. I spend so much on this, and I could guess the solution is just one line code.

  • 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-07T17:47:26+00:00Added an answer on June 7, 2026 at 5:47 pm

    cast the content of the button to an System.Xml.XmlElement. Then use the InnerText property of this element. Or maybe you have to do some more operation to get to your text. It depends on how your XML file is built.

    Rq : when i need to distinguish several identical controls in code, i use Tags. So i can set content and Tag independantly (required for multi-language apps.) or even use a ‘tag-logic’when choosing the Tag (prefixe/suffixes, index, …) which simplify handling in code.

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

Sidebar

Related Questions

I have a listbox that's binded to data, each item that's in the listbox
I have listbox, button, and textbox controls in a Windows application. How can I
I have a listbox that a user can select multiple values from . each
i have made a listbox datatemplated with button and binded to a textbox. i
i have listbox that reads a xml file and gives the user the ability
I have a typical MVVM scenario: I have a ListBox that is binded to
I have listbox which binds data to DataTable and now I need to access
I have a listbox that users can add/remove from. To add, there's a text
I have implemented a listbox with buttons as follows <Button.Content> <StackPanel Orientation=Horizontal Width=440 Height=210>
I have ListBox data bind to list of users (collection): usersListBox.DataSource = null; usersListBox.DataSource

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.