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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:48:24+00:00 2026-05-14T02:48:24+00:00

I’ve got listbox that employs an item template. Within each item in the list,

  • 0

I’ve got listbox that employs an item template. Within each item in the list, as defined in the template there is a button. When the user clicks the button I change a value in the data source that defines the sort order of the list. Changing the datasource is not a problem as this is working just fine within my application template.

However my next step is to reload the listbox with the new sorted data source. I’ve tried doing this from the tempalte but it apparently doesn’t have access (or I can’t figure out how to get access) to the parent elements so I can reset the .ItemSource property with a newly sorted data source.

Seems like this is possible but the solution is eluding me 🙁

  • 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-14T02:48:25+00:00Added an answer on May 14, 2026 at 2:48 am

    You could use databinding to bind the Button’s Tag to its ListBox ancestor. Example:

    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="myDataTemplate">
                <Button Tag="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}}"
                            Click="Button_Click">MyButton</Button>
            </DataTemplate>
        </Grid.Resources>
    
        <ListBox ItemTemplate="{StaticResource myDataTemplate}" ItemsSource="..." />
    </Grid>
    

    And here’s the codebehind:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ListBox myListBox = (ListBox)((Button)sender).Tag;
            ...do something with myListBox...
        }
    

    Alternatively, you can manually climb the Visual Tree upwards in your code (no Tag data binding needed):

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DependencyObject search = (DependencyObject)sender;
            while (!(search is ListBox)) {
                search = VisualTreeHelper.GetParent(search);
            }
            ListBox myListBox = (ListBox)search;
            ...do something with myListBox...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
i got an object with contents of html markup in it, for example: string

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.