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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:02:26+00:00 2026-06-11T05:02:26+00:00

(using VS 2010) I’m new to WPF and am trying to create a TreeViewItem

  • 0

(using VS 2010) I’m new to WPF and am trying to create a TreeViewItem that displays 2 images, then some text. To do this I’m using StackPanel. I want the first image to show/hide depending upon changes to model property, so I added a trigger to set its width to 0:

 <TreeView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Children}">

                <StackPanel Orientation="Horizontal" Margin="2" SnapsToDevicePixels="True" Width="Auto">
                    <Image Width="16" Height="16">
                        <Image.Style>
                            <Style TargetType="{x:Type Image}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding LinkType}" Value="Co">
                                        <Setter Property="Source" Value="/Images/Image1.png"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding LinkType}" Value="Post">
                                        <Setter Property="Width" Value="0"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>

                    <Image Source="/Images/Image2.png"
                        Width="15"
                        Height="15"
                        SnapsToDevicePixels="True" Margin="3,0"/>
                    <TextBlock Text="{Binding Name}" Margin="5,0" />
                </StackPanel>



            </HierarchicalDataTemplate>
        </TreeView.ItemTemplate>

This does in fact hide the image, but leaves an empty gap- the remaining items in the stackpanel do not slide to the left to account for the “removal” of the first image. I also tried triggering to Visibility with same results.

Is there a way I can add/remove, or show/hide, or change width=0, etc, items in StackPanel so that the remaining items readjust their positions accordingly? Or is there a better container than stackpanel for this?

  • 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-11T05:02:28+00:00Added an answer on June 11, 2026 at 5:02 am

    Yes. When you are using a TreeView, the direct “children” of the TreeView are not actually your Image controls – your Image controls are contained within TreeViewItem controls. These are generated automatically and allow the TreeView to handle its children in a more intuitive way (without forcing all controls to implement the properties/functions required of a TreeView child).

    It’s easy to customize these TeeViewItems. They share the same DataContext as your Images, so you can set the TreeView.ItemContainerStyle like so:

    <TreeView>
        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding LinkType}" Value="Post">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                </Style.Triggers> 
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SharePoint 2010. I want to create new view for my list. The
I'm using Excel 2010. I'm trying so save my excel file, with this code.
I am using VS 2010, trying to debug (F5) a solution that is saved
I am using SharePoint 2010 and have a customized newform.aspx and editform.aspx that I
I'm using Excel 2010 to read some SQL data using an ODBC data connection.
Using Delphi 2010, let's say I've got a class declared like this: TMyList =
Using TFS 2010. I have created a number of new Build Definitions. I also
I am using VS 2010 unit tests to create a load test. BeginTimer/EndTimer are
Using VS 2010 beta 2, ASP.NET MVC. I tried to create an Entity framework
Using Word 2010 GUI, there is an option to Insert text from file..., which

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.