Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF listbox empty item template not showing
    primarykey
    data
    text
    <p>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.</p> <pre><code> &lt;ListBox Name="itemsCtrl" Background="#FFE5E5E5" BorderBrush="{x:Null}" SelectionChanged="itemsCtrl_SelectionChanged" Style="{StaticResource ListStyle}"&gt; &lt;ListBox.Resources&gt; &lt;!-- Set SelectedItem Background here --&gt; &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#C2C2C2"/&gt; &lt;Style TargetType="{x:Type ListBoxItem}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True"&gt; &lt;Setter Property="Background" Value="#C2C2C2" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;Style TargetType="ListBox" x:Key="ListStyle" BasedOn="{StaticResource {x:Type ListBox}}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}" Value="0" &gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;TextBlock&gt;No items to display&lt;/TextBlock&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ListBox.Resources&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Cursor="Hand" Name="hoverDataTemplate" Orientation="Horizontal" Width="370" VerticalAlignment="Top" Height="40" HorizontalAlignment="Left" &gt; &lt;Label VerticalContentAlignment="Center" HorizontalAlignment="Left" Padding="15,5,5,5" Width="330" Content="{Binding Path=EVENT_TITLE}" FontSize="12"/&gt; &lt;Image Height="28" Source="/pr;component/Images/black_next.png" Stretch="Fill" Width="28" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>And I am binding data source as shown below.</p> <pre><code> itemsCtrl.ItemsSource = dao.SelectDataTable(cmd).DefaultView; </code></pre> <p>When I set the style property of ListBox as ListStyle it is throwing an error</p> <pre><code>'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '292' and line position '22'. </code></pre> <p>Can anybody point out how to make it correct?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload