使用 IValueConverter

问题描述

我有一个显示搜索结果的列表框,按类型分组,实现如下:

<ListBox.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style targettype="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Expander IsExpanded="True">
                                <Expander.Header>
                                    <TextBlock Margin="10 5 0 0">
                                        <TextBlock.Text>
                                            <MultiBinding StringFormat="{}{0}: {1}">
                                                <Binding Path="Name" />
                                                <Binding Path="ItemCount" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>
                                </Expander.Header>
                                <Expander.Content>
                                    <ItemsPresenter />
                                </Expander.Content>
                            </Expander>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ListBox.GroupStyle>

这工作正常。

现在,如果组中有 10 个或更多项目,我想折叠扩展器(仅在计数更改后,保留用户手动展开和折叠的可能性)。我怎样才能做到这一点?

我写了一个 IsLessthanConverter : IValueConverter,它接受​​一个参数,如果传递的值小于参数,则返回 true。

但是,我不知道如何在此处集成此转换器。我尝试过这样的事情,但从未调用转换器:

<Expander IsExpanded="{Binding Path=Count,RelativeSource={RelativeSource Self},Converter={StaticResource IsLessthanConverter},ConverterParameter=10,Mode=OneWay}">
    ...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...