WPF Listbox - Empty List Display Message WPF Listbox - Empty List Display Message wpf wpf

WPF Listbox - Empty List Display Message


The problem in your code is that setting the value of Visibility in the text block itself has higher priority than setting it in the style. So, even when the trigger occurs, the setting inside the trigger has no effect. Change the XAML to:

  <TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="List is empty" >    <TextBlock.Style>        <Style TargetType="{x:Type TextBlock}">           <Setter Property="Visibility" Value="Collapsed" />            <Style.Triggers>                <DataTrigger Binding="{Binding ElementName=lstItems, Path=Items.Count}" Value="0">                    <Setter Property="Visibility" Value="Visible" />                </DataTrigger>              </Style.Triggers>        </Style>                                </TextBlock.Style>  </TextBlock>

Where the setting of Visibility is all in the style and it works (at least in my demo project).