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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:21:48+00:00 2026-05-15T23:21:48+00:00

I’m currently binding an xml file to a listbox in C# WPF. Within the

  • 0

I’m currently binding an xml file to a listbox in C# WPF. Within the itemtemplate I added controls. as follows:

<DataTemplate x:Key="SinglecueTemplate">
            <Grid Height="30" Width="425" Margin="3,3,0,3">
                <Button Content="{Binding XPath=nr}" Width="30" Style="{DynamicResource CUEStyle_Button_Inhoudknopje}" Template="{DynamicResource CUEStyle_singlecueknopnummer}" Height="Auto" HorizontalAlignment="Left" Background="#FFABCCED" Foreground="White" IsEnabled="False"/>
                <TextBlock x:Name="name" Margin="54,0,114.667,0" Width="Auto" VerticalAlignment="Center" FontSize="16" Foreground="Gray" Text="{Binding XPath=Name}"/>
                <Button x:Name="playbutton" Width="30" Style="{DynamicResource CUEStyle_Button_Groot}" Template="{DynamicResource CUEStyle_Rondknopje}" Height="Auto" HorizontalAlignment="Right" Margin="0,0.55,74.737,-0.55" Content="u" FontFamily="Wingdings 3" Foreground="#FF0178D3" Opacity="1" BorderBrush="#FF0178D3" Click="playcue"/>
                <Button Width="30" Style="{DynamicResource CUEStyle_Button_Groot}" Template="{DynamicResource CUEStyle_Rondknopje}" Height="Auto" HorizontalAlignment="Right" Margin="0,0.55,37.071,-0.55" Content="¢" FontFamily="Wingdings 2" Foreground="Gray" Opacity="0.4"/>
                <Button Width="15" Style="{DynamicResource CUEStyle_Button_Groot}" Template="{DynamicResource CUEStyle_kleinloopje}" Height="15" HorizontalAlignment="Left" Margin="15,0,0,-5.5" Content="Q" FontFamily="Wingdings 3" Foreground="White" FontWeight="Bold" FontSize="10.667" Opacity="1" VerticalAlignment="Bottom" BorderBrush="{x:Null}" Background="{x:Null}" IsEnabled="{Binding XPath=Loop}"/>
                <TextBlock Margin="0,0,114.667,0" Width="81.07" VerticalAlignment="Center" FontSize="16" Foreground="Gray" Text="03:02:11" HorizontalAlignment="Right"/>
            </Grid>
        </DataTemplate>

Now when a the playbutton is clicked I want to acces other properties from that listboxitem, for example the text from the text block. I looked up on how to do this and came up with the following:

            private void playcue(object sender, System.Windows.RoutedEventArgs e)
            {
                Button playcue = (Button)sender;
                Textbox titel = (Textbox)playcue.DataContext;
                MessageBox.Show(titel);
            }

But the code above gives me an error stating that the type Textbox is unknown. Do I have to do something with the datatemplate so that I can acces other items within the template? Or is it possible to access sibling nodes from the datasource?

UPDATE

Answer found. Now for future reference:

private void playcue(object sender, System.Windows.RoutedEventArgs e)
            {
                Button playcue = (Button)sender;
                XmlElement name = (XmlElement)playcue.DataContext; 
                MessageBox.Show(name.InnerText);

            }

Returns all sibling values from the item

If you want to access a specific sibling you can do so:

MessageBox.Show(name.SelectSingleNode("Name").InnerXml);
  • 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-15T23:21:49+00:00Added an answer on May 15, 2026 at 11:21 pm

    First problem is that it’s TextBox not Textbox (C# is case sensitive.)

    Second, it’s unlikely that your DataContext is a TextBox. It should be an item in your ItemsSource collection. So, if the user clicks the third button in the list, you should be looking at the 3rd item in your ItemsSource collection. Since it appears you are using XML as a data source, I would guess that the item should be an XElement or an XmlElement.

    I suggest you change Textbox titel = (Textbox)playcue.DataContext; to the following:

    XElement element = (XElement)playcue.DataContext;
    

    or

    XmlElement element = (XmlElement)playcue.DataContext;
    

    You will also need to change your MessageBox statement as well.

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

Sidebar

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.