Following is the syntax for my listview which is binded to a class....
<ListView ItemContainerStyle="{StaticResource listViewStyle}" Name="transactionListView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding}" MouseDoubleClick="transactionListView_MouseDoubleClick" IsSynchronizedWithCurrentItem="True" >
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource gridViewHeaderColumnStyle}">
<GridView.Columns>
<GridViewColumn Width="70" Header="Serial" DisplayMemberBinding="{Binding Path=Serial}" />
<GridViewColumn Width="100" Header="Date" DisplayMemberBinding="{Binding Path=Date, StringFormat={}{0:dd-MM-yyyy}}" />
<GridViewColumn Width="200" Header="Seller" DisplayMemberBinding="{Binding Path=Seller}" />
<GridViewColumn Width="200" Header="Buyer" DisplayMemberBinding="{Binding Path=Buyer}" />
<GridViewColumn Width="70" Header="Bales" DisplayMemberBinding="{Binding Path=Bales}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
*How can i display some text when the list is empty or contain no items?
The trick is in overriding ListView's template. When there are no items in ListView you should set your ControlTemplate with TextBlock:
<ListView Name="List" ItemsSource="{Binding Items}">
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<Trigger Property="HasItems"
Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<TextBlock Text="No items..."/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>
The ListView itself does not supply this functionality. The simplest approach is to place a TextBlock in front of the ListView with its Visibility set to Collapsed. You can then make it Visible when your list has no items in it.
If you need help with the specific, please expand your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With