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

[Solved] updated EmptyDataTemplate?

8 Answers 201 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mike
Top achievements
Rank 1
Mike asked on 14 Aug 2010, 12:34 AM
Hi.

I tried to use the following EmptyDataTemplate:
http://blogs.telerik.com/blogs/posts/10-02-01/empty_data_template_in_radgridview_for_silverlight_and_wpf.aspx
but it fails to work as expected with RadControls_for_Silverlight 2010_2_0812.

Any ideas on how to get it working again?

Any other ideas about the ArgumentOutOfBoundsException  that occurs if gridView.ChildrenOfType<Grid>().Count == 0?

Thank you.

8 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 18 Aug 2010, 10:13 AM
Hello Mike,

I have prepared an updated project for you. Please find it attached. Should work with the new binaries.
Let me know in case you have troubles with it.

All the best,
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
0
Mike
Top achievements
Rank 1
answered on 19 Aug 2010, 02:14 AM
Thank you Pavel,

Your example works as-is.

However, in my scenario, I am getting an exception:
System.ArgumentOutOfRangeException was unhandled by user code
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  StackTrace:
       at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Collections.Generic.List`1.get_Item(Int32 index)
       at NoItemsPanel.EmptyDataTemplateBehavior.AssociatedObject_LayoutUpdated(Object sender, EventArgs e)
       at System.Windows.FrameworkElement.OnLayoutUpdated(Object sender, EventArgs e)
       at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)

This happens when a new instance of the control with the EmptyDataTemplate is created but is not visible.

For example, using the example project given, simple replace the line in App.xaml.cs:
this
.RootVisual = new MainPage();
to
MainPage page = new MainPage();

In my real scenario, I am actually using a RadFrameContainer and dynamically displaying RadPages and the EmptyDataTemplate is on the second RadPage for example, but this simple change in the example project given produces the same unexpected behavior.

Any advice?

Thank you.
0
Accepted
Pavel Pavlov
Telerik team
answered on 19 Aug 2010, 12:28 PM
Hi Mike,

I think I have found the problem . I have updated the project on my blog post. You may download the updated project here.


The updated method looks like :
void AssociatedObject_LayoutUpdated(object sender, EventArgs e)
       {
           Grid rootGrid = this.AssociatedObject.ChildrenOfType<Grid>().FirstOrDefault();
             
           if (rootGrid != null)
           {
               this.AssociatedObject.LayoutUpdated -= new EventHandler(AssociatedObject_LayoutUpdated);
               this.LoadTemplateIntoGridView(this.AssociatedObject);
               this.AssociatedObject.Items.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Items_CollectionChanged);
               SetVisibility();
           }
       }


A small change regarding the access of the child grid was made -
instead of accessing by index the  FirstOrDefault(); method is used.

All the best,
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
0
Mike
Top achievements
Rank 1
answered on 19 Aug 2010, 10:50 PM
Thank you Pavel,

It works!

I am now trying to figure out how to bind the IsEnabled property of the EmptyDataTemplate with the RadGridView.

Any advice?

Thank you.
0
Pavel Pavlov
Telerik team
answered on 20 Aug 2010, 07:41 AM
Hi Mike,

At the end of the LoadTemplateIntoGridView method, you may add a line to perform the binding.

Here you have access to the content presenter and may use SetBinding to do whatever you need.

I am not sure what exactly you are trying to achieve , as the DataTemplate does not have IsEnabled property.

If you give me a bit more details on the desired behavior I will gladly provide the code for you .

All the best,
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
0
Mike
Top achievements
Rank 1
answered on 20 Aug 2010, 09:16 PM
Thanks Pavel,

In the case where RadGridView.IsEnabled = false and there are no items in its datasource, the EmptyDataTemplate is displayed correctly, but I would have expected it to inherit the .IsEnabled property of the RadGridView such that the Border and the TextBlock in the DataTemplate are grayed out.

Thank you.
0
Accepted
Milan
Telerik team
answered on 23 Aug 2010, 11:15 AM
Hello Mike,

You can do that by tweaking the EmptyDataTemplateBehavior.cs a bit. First you should change the type of the contentPresenter variable to ContentControl which has an IsEnabled property. Then you need to setup the binding of IsEnabled in LoadTemplateIntoGridView:

// tie the IsEnabled property of the presenter to IsEnabled of the grid 
Binding binding = new Binding("IsEnabled");
binding.Source = this.AssociatedObject;
contentPresenter.SetBinding(ContentControl.IsEnabledProperty, binding);

Once you do that, all controls inside the EmptyDataTemplate will be disabled when the grid is disabled. Unfortunately some controls like TextBlock will not change their visual appearance when disabled. If you would like to have a greyed-out text when RadGridView is disabled you can use another type of control - Label for example which is part of the Silverlight toolkit. This control does not change its visual style by default but you can redefine its template and achieve the desired result:

<local:EmptyDataTemplateBehavior>
    <local:EmptyDataTemplateBehavior.EmptyDataTemplate>
        <DataTemplate>
            <input:Label Content="sdfsdf" >
                <input:Label.Style>
                    <Style TargetType="input:Label">
                        <Setter Property="IsTabStop" Value="False"/>
                        <Setter Property="HorizontalContentAlignment" Value="Left"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="input:Label">
                                    <Grid>
                                        <vsm:VisualStateManager.VisualStateGroups>
                                            <vsm:VisualStateGroup x:Name="CommonStates">
                                                <vsm:VisualState x:Name="Normal"/>
                                                <!-- add state chane when Disabled-->
                                                <vsm:VisualState x:Name="Disabled">
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentControl" Storyboard.TargetProperty="Foreground" Duration="0:0:1.5">
                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <SolidColorBrush Color="Gray" />
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                            <vsm:VisualStateGroup x:Name="ValidationStates">
                                                <vsm:VisualState x:Name="Valid"/>
                                                <vsm:VisualState x:Name="Invalid">
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentControl" Storyboard.TargetProperty="Foreground" Duration="0:0:1.5">
                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <SolidColorBrush Color="Red" />
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                            <vsm:VisualStateGroup x:Name="RequiredStates">
                                                <vsm:VisualState x:Name="NotRequired"/>
                                                <vsm:VisualState x:Name="Required">
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentControl" Storyboard.TargetProperty="FontWeight" Duration="0">
                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="SemiBold"/>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </vsm:VisualState>
                                            </vsm:VisualStateGroup>
                                        </vsm:VisualStateManager.VisualStateGroups>
                                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" CornerRadius="2">
                                            <ContentControl x:Name="ContentControl" Foreground="{TemplateBinding Foreground}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" FontWeight="{TemplateBinding FontWeight}" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" VerticalAlignment="{TemplateBinding VerticalAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsTabStop="False" />
                                        </Border>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </input:Label.Style>
            </input:Label>
  
            <!--<TextBlock Text="No results found!" HorizontalAlignment="Center"  VerticalAlignment="Center" Visibility="{Binding MessageVisibility}" />-->
            <!--<Button Content="sdfsd"/>-->
        </DataTemplate>
    </local:EmptyDataTemplateBehavior.EmptyDataTemplate>

Sincerely yours,
Milan
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
0
Mike
Top achievements
Rank 1
answered on 24 Aug 2010, 12:05 AM
Perfect!

Thank you very much! :)

xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mike
Top achievements
Rank 1
Milan
Telerik team
Share this question
or