WPF列表框为空的DataTemplate为空、列表、WPF、DataTemplate

由网友(敬你一杯烈酒)分享简介:我想知道人们是如何处理ListBox控件,有没有项目?例如我要绑定的搜索结果列表,但如果没有结果发现我想显示没有找到结果。 I was wondering how people handle a ListBox control that has no items? e.g. I want to bind a list...

我想知道人们是如何处理ListBox控件,有没有项目?例如我要绑定的搜索结果列表,但如果没有结果发现我想显示没有找到结果。

I was wondering how people handle a ListBox control that has no items? e.g. I want to bind a list of search results but if no results are found i would like to display "No results found".

我的样子当前解决。这是我隐藏列表框,如果结果集计数= 0,并显示有未找到结果消息的标签。我非常希望类似的ASP .NET的DataGrid EmptyTemplate解决方案。

The way i currently tackle this is that i hide the listbox if the result set count = 0 and show a label with the "No results found" message. Ideally i would like something like the ASP .NET datagrid EmptyTemplate solution.

干杯

推荐答案

我已经受够了这种code一定的成功:

I've had some success with this code:

<Style TargetType="ListBox" x:Key="ListStyle" BasedOn="{StaticResource {x:Type ListBox}}">
    <Style.Triggers>
        <DataTrigger 
            Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}" 
            Value="0"
            >
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <TextBlock>No items to display</TextBlock>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>
阅读全文

相关推荐

最新文章