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 8743589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:42:21+00:00 2026-06-13T11:42:21+00:00

I am try to list some data in WPF listbox control. It is the

  • 0

I am try to list some data in WPF listbox control. It is the first time I am using DataTemplate in WPF. Everything is working fine except when there is no data it is not showing ‘No items to display’. Below is my code.

    <ListBox Name="itemsCtrl" Background="#FFE5E5E5" BorderBrush="{x:Null}" SelectionChanged="itemsCtrl_SelectionChanged" Style="{StaticResource ListStyle}">

        <ListBox.Resources>
            <!-- Set SelectedItem Background here -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#C2C2C2"/>
            <Style TargetType="{x:Type ListBoxItem}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsMouseOver,
                                    RelativeSource={RelativeSource
                                      Self}}"
                        Value="True">
                        <Setter Property="Background"
                         Value="#C2C2C2" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
            <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>
        </ListBox.Resources>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Cursor="Hand" Name="hoverDataTemplate" Orientation="Horizontal" Width="370" VerticalAlignment="Top" Height="40" HorizontalAlignment="Left" >
                    <Label VerticalContentAlignment="Center" HorizontalAlignment="Left" Padding="15,5,5,5" Width="330"  Content="{Binding Path=EVENT_TITLE}" FontSize="12"/>
                    <Image Height="28" Source="/pr;component/Images/black_next.png" Stretch="Fill" Width="28" />

                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

And I am binding data source as shown below.

    itemsCtrl.ItemsSource = dao.SelectDataTable(cmd).DefaultView;

When I set the style property of ListBox as ListStyle it is throwing an error

'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '292' and line position '22'.

Can anybody point out how to make it correct?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 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-06-13T11:42:22+00:00Added an answer on June 13, 2026 at 11:42 am

    i have used below code and it’s work fine
    my xaml code

    <ListBox Grid.ColumnSpan="2" Grid.Row="1" Height="32" HorizontalAlignment="Left" Margin="160,2,0,0" Name="listBox1" VerticalAlignment="Top" Width="120" Style="{StaticResource Dhaval}"/>
    

    Style look like

    <Style x:Key="Dhaval" TargetType="{x:Type ListBox}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a List to hold some data obtained by calling Array.asList() method.
I have a UIManagedDocument with some data which I display in a list using
I try to make a displaying list with onmouseover() with some links but they
I load some images into an object list , and then try to recall
I am using the following to try and list all the files in a
Why is this for ((;;)); do sl; done; not working? I try to list
I have a string comma separated list of some data. I have another list
Here is my class where I try to get into a JSONArray some data
The below GUI simply lists some data in a listbox, plots it, and gives
I'm trying to grab some data using Selenium and xpaths. The following xpath works

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.