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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:14:20+00:00 2026-05-17T20:14:20+00:00

I have a TreeView whose contents (nested TreeViewItems) are generated from a dataset via

  • 0

I have a TreeView whose contents (nested TreeViewItems) are generated from a dataset via databinding, which all seems to work fine. The issue I’m running into is that when I try and manipulate the contents of the TreeViewItem headers in code, the Header property returns the DataRowView that the TreeViewItem was generated from and not, as I was expecting, the control generated by the template.

Here’s an example of the template I’m using to generate the TreeViewItems:

    <DataTemplate x:Key="seasonTreeViewItemTemplate">
        <TreeViewItem>
            <TreeViewItem.Header>
                <CheckBox Content="{Binding Path=Row.SeasonID}" Tag="{Binding}" ToolTip="{Binding Path=Row.Title}" IsEnabled="{StaticResource seasonPermitted}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />
            </TreeViewItem.Header>

            <TreeViewItem Header="Championships" ItemTemplate="{StaticResource championshipTreeViewItemTemplate}">
                <TreeViewItem.ItemsSource>
                    <Binding Path="Row" ConverterParameter="FK_Championship_Season">
                        <Binding.Converter>
                            <local:RowChildrenConverter />
                        </Binding.Converter>
                    </Binding>
                </TreeViewItem.ItemsSource>
            </TreeViewItem>
        </TreeViewItem>
    </DataTemplate>

Can anyone point out where I’m going wrong and advise me how to access the header checkboxes (ideally without delving into the VisualTree if possible)?

Thanks,
James

  • 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-17T20:14:21+00:00Added an answer on May 17, 2026 at 8:14 pm

    Well, after some searching I have found an adequate solution to the problem.

    Using the following code, you can find named items in the template:

    if (treeViewItem != null)
    {
            //Get the header content presenter.
            ContentPresenter header = treeViewItem.Template.FindName("PART_Header", treeViewItem) as ContentPresenter;
    
            if (header != null)
            {
                //Find a CheckBox called "checkBoxName"
                CheckBox cb = treeViewItem.HeaderTemplate.FindName("checkBoxName", header) as CheckBox;
            }
    } 
    

    Also, for the benefit of anyone else who may not be too clued up on databinding treeviews: The template I posted in my question is not the right way to go about binding a treeview. Use a HierarchicalDataTemplate for each level of the tree. The direct content of the HierarchicalDataTemplate will specify the header content of each subtree and setting the ItemsSource and ItemTemplate properties will allow you to bind and format the subtrees children, for example:

    <HierarchicalDataTemplate x:Key="templateName" ItemsSource="{Binding Path=someCollection}" ItemTemplate="{StaticResource someOtherTemplate}">
        <TextBlock Text="{Binding Path=SomeProperty}" />
    </HierarchicalDataTemplate>
    

    I hope someone else will find this information useful.

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

Sidebar

Related Questions

I have a treeview control on an aspx page. The data comes from database
I have a TreeView whose ItemsSource is set to a Model I have. 3
I have a TreeView which i build up in code recursively. I would like
Ok, I have a treeview which I am using to display a number of
I have a treeview control in a Windows Forms project that has checkboxes turned
I have a TreeView control in my WinForms .NET application that has multiple levels
I have a treeview with nodes like this: Foo (1234), and want to allow
I have a TreeView windows forms control with an ImageList , and I want
I have a treeview in my masterpage. When a contentpage is loaded i want
Using WPF, I have a TreeView control that I want to set its ItemTemplate

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.