Text to display when empty

2 posts, 0 answers
  1. Mark
    Mark avatar
    35 posts
    Member since:
    Nov 2008

    Posted 08 Nov 2012 Link to this post

    Hello,

    How can I show a specific text string when a RadListBox instance is empty?

    I tried defining a style to accomplish this goal, like this:

    <Style TargetType="telerik:RadListBox" x:Key="ListStyle" BasedOn="{StaticResource {x:Type telerik:RadListBox}}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}" Value="0">
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Top"/>
                <Setter Property="Margin" Value="0, 20, 0, 0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <TextBlock Foreground="DimGray" TextWrapping="Wrap" FontSize="14">
                                There are currently no items to show.
                            </TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    I then attach it to the RadListBox instance:

    <telerik:RadListBox  Style="{StaticResource ListStyle}">
       // items here
    </telerik:RadListBox>

    This actually works, for the most part... but it has a fatal flaw - the RadListBox scrollbars are no longer correctly themed.

    Is there another way of accomplishing this goal? Or could I get some help in tweaking the style above so that the vertical scrollbar has the correct "Windows7" theme applied to it?
  2. Masha
    Admin
    Masha avatar
    355 posts

    Posted 13 Nov 2012 Link to this post

    Hello Mark,

    I guess you are using StyleManager. The problem occurs because when you use BasedOn="{StaticResource {x:Type telerik:RadListBox}}", you overwrite Windows7 Theme with default one which is OfficeBlack. You should copy RadListBoxStyle, search telerik:StyleManager.Theme="{StaticResource Theme}" and replace with telerik:StyleManager.Theme="Windows7".

    I would also recommend using Implicit Styles to apply Windows7 Theme, more about them you can find in this help article. In this case you do not have to make any modifications to your custom RadListBoxStyle.

    Hope it helps.

    Greetings,
    Maria
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top