我使用ListView
和GridView
视图来显示搜索结果。在没有要显示的元素的情况下,我想在ListView
的中间显示信息性消息(类似“找不到元素”)。我怎么能这样做?
答案 0 :(得分:1)
当ListView没有项目时,您可以使用触发器更改ListView模板,如下所示:
<ListView Name="List"
DockPanel.Dock="Top"
ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="70" Header="Serial" DisplayMemberBinding="{Binding Path=Serial}" />
</GridView.Columns>
</GridView>
</ListView.View>
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<Trigger Property="HasItems"
Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<StackPanel>
<ListView>
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="70" Header="Serial" DisplayMemberBinding="{Binding Path=Serial}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
<TextBlock Text="No items..."/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>