1

I have a Wrappanel inside a TreeViewItem. The Items inside the Wrappanel can be made (in)visible by a filter. The problem is that the collapsed Items still need a small place what corrupts the alignment (all Items have a fixed width, Margin and Padding is 0).
How can I remove the superfluous space?

Part of the XAML (inside the TreeViewItem Style):

<Setter Property="ItemsPanel">
    <Setter.Value>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
    <Setter.Value>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Assigned, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      ToolTip="{Binding Description}"
                      Click="CheckBox_Clicked"
                      FontFamily="Courier New"
                      Padding="0,0,0,0"
                      Margin="0,0,0,0">
                <TextBlock Text="{Binding FixedLengthName}"/>
                <CheckBox.Visibility>
                    <MultiBinding Converter="{StaticResource PermVisibilityConv}">
                        <Binding Path="IsChecked" ElementName="ChangesOnly"/>
                        <Binding Path="Changed"/>
                        <Binding Path="Visible"/>
                    </MultiBinding>
                </CheckBox.Visibility>
            </CheckBox>
        </DataTemplate>
    </Setter.Value>
</Setter>

without filter:
all items visible

with filter:
some items collapsed

Breeze
  • 2,010
  • 2
  • 32
  • 43
  • you can't use size on the textblock /checkbox ? and not FixedLengthName , text length is not size fixed – ZSH Oct 26 '15 at 09:43
  • BTW - replacing the wrappanel with unifomgrid with columns=3 will result in same size item in 3 columns – ZSH Oct 26 '15 at 09:44
  • @ZSH FixedLengthName is of fixed length, I make that sure in my code and it works properly, don't worry about that. Thanks for the hint about uniformgrid, but I really want a wrappanel because I want more or less columns when the window width changes – Breeze Oct 26 '15 at 10:35
  • OK, i suggest that you check the width of the textblocks with snoop make sure it's equal – ZSH Oct 26 '15 at 12:07
  • @ZSH checked it with Snoop: all visible Items have the same ActualWidth (281,4766...), the collapsed Items have ActualWidth 20 – Breeze Oct 26 '15 at 12:49
  • The Checkbox itself has an ActualWidth of 0, but there's overhead (Expander, Border etc.) that has the ActualWidth that corrupts the alignment – Breeze Oct 26 '15 at 13:09

1 Answers1

1

Thanks to the help of ZSH, I found a solution.
It's not enough to Collapse the CheckBox, the Container around it also must be collapsed.
After I moved the Visibility-Binding from the CheckBox to the ItemContainerStyle, the View behaved as it should.

the same part of the XAML as above, now without space occupied by collapsed Items:

<Setter Property="ItemsPanel">
    <Setter.Value>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
    <Setter.Value>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="Visibility">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource PermVisibilityConv}">
                        <Binding Path="IsChecked" ElementName="ChangesOnly"/>
                        <Binding Path="Changed"/>
                        <Binding Path="Visible"/>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>
    </Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
    <Setter.Value>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Assigned, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                      ToolTip="{Binding Description}" Click="CheckBox_Clicked"
                      FontFamily="Courier New">
                <TextBlock Text="{Binding FixedLengthName}"/>
            </CheckBox>
        </DataTemplate>
    </Setter.Value>
</Setter>
Breeze
  • 2,010
  • 2
  • 32
  • 43
  • sometimes all it takes is someone to walk through the facts with you ,glad to help – ZSH Oct 27 '15 at 09:50