No data template

4 posts, 0 answers
  1. Patrick
    Patrick avatar
    55 posts
    Member since:
    Jun 2008

    Posted 15 Aug 2010 Link to this post

    I would like for the RadGridView to display something like "No data to display" when there are no bound items to the RadGridView. I found some code online which solves the problem, however I would like to define it application wide.

    I attempted to subclass RadGridView which compiles fine. However, whenever I use this subclass I get a compiler error, "

    Cannot set Name attribute value {0} on element {1}. {1} is under the scope of element {2}, which already had a name registered when it was defined in another scope."


    Which I guess is a known limitation of WPF. I would just like to specify the no row template once since I have an application with 30+ instances of RadGridView.

    The code I found is from here, and is listed below:

        <interactivity:Interaction.Behaviors>
        <local:EmptyDataTemplateBehavior>
            <local:EmptyDataTemplateBehavior.EmptyDataTemplate>
                <DataTemplate>
                    <TextBlock Text="No data to display" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding MessageVisibility}" />
                </DataTemplate>
            </local:EmptyDataTemplateBehavior.EmptyDataTemplate>
        </local:EmptyDataTemplateBehavior>
    </interactivity:Interaction.Behaviors>
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 18 Aug 2010 Link to this post

    Hi Patrick,

    Please use the attached project for reference. It has an inherited RadGridView, which encapsulates the logic for the no items message. This way  there is no need to use attached behavior at all.


    Greetings,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Patrick
    Patrick avatar
    55 posts
    Member since:
    Jun 2008

    Posted 18 Aug 2010 Link to this post

    Very nice.
    Thank you.
  5. Brian Stanek
    Brian Stanek avatar
    15 posts
    Member since:
    Jan 2008

    Posted 28 Aug 2015 Link to this post

    I know that this is a very old post, but I have seen it referenced a few times and ran into it myself as a suggested solution.  But I have found an easier method using a BooleanToVisibility converter.  And this is a pure XAML solution.

    <telerik:RadGridView x:Name="gridView"
             ItemsSource="{Binding Path=PolicyTypeList}"
             IsReadOnly="True" CanUserSortGroups="False"
             ShowGroupPanel="False" EnableLostFocusSelectedState="True"
             IsFilteringAllowed="False"
             ColumnWidth="*"
             RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">
    <telerik:RadGridView.ChildTableDefinitions>
    <telerik:GridViewTableDefinition />
    </telerik:RadGridView.ChildTableDefinitions>
    <telerik:RadGridView.HierarchyChildTemplate>
    <DataTemplate>
        <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0"
               Visibility="{Binding ItemsSource.IsEmpty, Converter={StaticResource BoolToVisible},ElementName=childGrid}"
               >No Policy Applications Found!</TextBlock>
        <telerik:RadGridView Name="childGrid" Grid.Row="1"                                         
               Visibility="{Binding ItemsSource.IsEmpty, Converter={StaticResource BoolToVisible},ConverterParameter=Invert,ElementName=childGrid}"
                 ItemsSource="{Binding Path=ChildRecords}"
                 IsReadOnly="True" CanUserSortGroups="False"
                 ShowGroupPanel="False" EnableLostFocusSelectedState="True"
                 IsFilteringAllowed="False"
                 Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}"
                 ColumnWidth="*"
                 RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
        </Grid>
    </DataTemplate>
    </telerik:RadGridView.HierarchyChildTemplate>
    <telerik:RadGridView.Columns>
    </telerik:RadGridView.Columns>
    </telerik:RadGridView>

Back to Top