Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 671333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:21:43+00:00 2026-05-14T00:21:43+00:00

Can anyone suggest the best way to display a Textblock (with a text such

  • 0

Can anyone suggest the best way to display a Textblock (with a text such as “List Empty”) so that it’s visibility is bound to the Items.Count.

I have tried the following code and can’t get it to work, so think that I must be doing it wrong.

    <ListBox x:Name="lstItems" 
        ItemsSource="{Binding ListItems}">
    </ListBox>
    <TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="List is empty" Visibility="Collapsed">
        <TextBlock.Style>
            <Style TargetType="{x:Type TextBlock}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=lstItems, Path=Items.Count}" Value="0">
                        <Setter Property="Visibility" Value="Visible" />
                    </DataTrigger>  
                </Style.Triggers>
            </Style>                            
        </TextBlock.Style>
    </TextBlock>
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:21:44+00:00Added an answer on May 14, 2026 at 12:21 am

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone suggest the best way to populate a list from an sqlite database.
Can anyone suggest the best way to offer a file for download within a
Can anyone suggest what software or tools that the best to design icon and
Can anyone suggest me which is the best way of displaying a PDF document
Can anyone suggest the best place to add solution or project events, such as
can anyone suggest the best way to serialize data (a class actually) to a
Can anyone suggest some best options to include charting feature in my ASP.NET pages
Can anyone suggest a way to shave any time off this script? var countObject
Can anyone suggest best method for what I want to accomplish? I have an
Does anyone have experience with / can anyone suggest best practices for storing quantities

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.