This is a migrated thread and some comments may be shown as answers.

Text to display when empty

1 Answer 274 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 08 Nov 2012, 07:55 PM
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?

1 Answer, 1 is accepted

Sort by
0
Masha
Telerik team
answered on 13 Nov 2012, 11:44 AM
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.

Tags
ListBox
Asked by
Mark
Top achievements
Rank 1
Answers by
Masha
Telerik team
Share this question
or