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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:03:14+00:00 2026-06-17T18:03:14+00:00

I don’t understand what wpf does here (using .NET 3.5 with C#): in my

  • 0

I don’t understand what wpf does here (using .NET 3.5 with C#):

in my Application Resources I defined several DataTemplates and HierarchicalDataTemplates for different Types of ViewModels. So far this works well, and the TreeView in my Window shows the Nodes like expected. I have to say that all Childelements in every ViewModel came as ICollectionView.
Now I decided to use the specialities of ICollectionView, to group, sort and filter the “Rootnodes” of the TreeView.
I made the TreeView look like this:

<TreeView ItemsSource="{Binding Path=Elements.Groups}">
  <TreeView.ItemTemplate>
    <HierarchicalDataTemplate ItemsSource="{Binding Path=Items}" ItemTemplate="{StaticResource SOMEITEMTEMPLATENAME}">
      <TextBlock Text="{Binding Path=Name}"/>
    </HierarchicalDataTemplate>
  </TreeView.ItemTemplate>
</TreeView>

The ViewModel looks like this:

class RootViewModel
  : INotifyPropertyChanged
{

  public ICollectionView Elements
  {
     get
     {
       ICollectionView view = CollectionViewSource.GetDefaultView(_elementsFromModel.Select(x => new FirstChildViewModel(x));
       view.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
       view.Filter = delegate(Object x) { /*do some filter stuff here*/ };

       return view;
     }
  }
}

class FirstchildViewModel
  : INotifyPropertyChanged
{
  /*some other stuff here*/

  public ICollectionView Items
  {
    get;
  }
}

The Problem now is that the TreeView doesn’t select autmatically the right Templates for the deeper childelements. So what is wrong with that?

  • 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-17T18:03:15+00:00Added an answer on June 17, 2026 at 6:03 pm

    The best solution, after some research would be to define the TreeView like this:

    <TreeView ItemsSource="{Binding Path=Elements}">
      <TreeView.GroupStyle>
        <GroupStyle>
          <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type GroupItem}">
                    <TreeViewItem>
                      <TreeViewItem.Header>
                        <TextBlock Text="{Binding Path=Name}"/>
                      </TreeViewItem.Header>
    
                      <ItemsPresenter Margin="-20,0,0,0"/>
                    </TreeViewItem>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </GroupStyle.ContainerStyle>
        </GroupStyle>
      </TreeView.GroupStyle>
    </TreeView>
    

    now the Group nodes are able to expand and collapse an the different childnodes use different DataTemplates. Thanks to @stukselbax for pointing me to the right direction.

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

Sidebar

Related Questions

Don't know what's wrong here, when I run the application it says Specified method
Don't know a whole lot about streams. Why does the first version work using
Don't want to sort the entries. using this does not preserve the order as
Don't think that I'm mad, I understand how php works! That being said. I
Don't know if I'm missing something here. I'd like to run multiple global variables
Don't know why this is happening, but after submitting a form via JS (using
Don't know why, but sometimes LocationManager is still working also after closing application. I
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering

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.