Wrappanel中的折叠物品仍需要放置 [英] Collapsed Items in Wrappanel still need place

查看:91
本文介绍了Wrappanel中的折叠物品仍需要放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TreeViewItem中有一个Wrappanel.可以通过过滤器使Wrappanel内部的项目可见(不可见).问题在于,折叠的项目仍需要一个较小的位置来破坏对齐方式(所有项目的宽度均固定,边距和填充为0).
如何删除多余的空间?

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?

XAML的一部分(在TreeViewItem样式内):

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:

带过滤器:

with filter:

推荐答案

借助ZSH的帮助,我找到了解决方案.
折叠CheckBox还不够,还必须折叠其周围的容器.
在将Visibility-Binding从CheckBox移到ItemContainerStyle之后,View的行为应为正常.

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.

与XAML相同的部分,现在没有折叠项占用的空间:

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>

这篇关于Wrappanel中的折叠物品仍需要放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆