EmptyDataTemplate RadGridView

36 posts, 0 answers
  1. Paloma
    Paloma avatar
    39 posts
    Member since:
    Mar 2009

    Posted 22 Apr 2009 Link to this post

    Hi everybody!!!
    Does anybody know if there's an EmptyDataTemplate for the RadGridView for Silverlight?
    Thanks
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 23 Apr 2009 Link to this post

    Hi Paloma,

    Do you mean a template that is shown when no data is present for the RadGridView at all or a template for the cell when the value is null ?

    All the best,
    Pavel Pavlov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Paloma
    Paloma avatar
    39 posts
    Member since:
    Mar 2009

    Posted 24 Apr 2009 Link to this post

    Hi Pavel,
    I mean a template that is shown when no data is present for the RadGridView at all.
    Thanks
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 28 Apr 2009 Link to this post

    Hello Paloma,

    Unfortunately we are missing that feature. I have already talked to my team and we have decided to schedule this  for the Q2 release. Meanwhile I can recommend using external panel placed "over" the RadGridView with your custom content or text. Listening to the ItemsSource collection changes and switching visibility of that panel should do the work .
    Let me know if you need further  help. I can  prepare  a sample for you .

    Greetings,
    Pavel Pavlov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Ravindranath Wickramanayake
    Ravindranath Wickramanayake avatar
    5 posts
    Member since:
    Jan 2010

    Posted 16 Feb 2010 Link to this post

    Could you please show sample code. thanks
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 17 Feb 2010 Link to this post

    Hi,

    You can check this post for more info:
    http://blogs.telerik.com/pavelpavlov/posts/10-02-01/empty_data_template_in_radgridview_for_silverlight_and_wpf.aspx

    Greetings,
    Vlad
    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.
  8. Milind Raje
    Milind Raje avatar
    37 posts
    Member since:
    May 2010

    Posted 04 Feb 2011 Link to this post

    hi,
    Has this been added already? if so what is the template format?
    thanks
    milind
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Feb 2011 Link to this post

    Hi,

    This is still not part of the grid - you can use the example from the blog post to achieve your goal. 

    Best wishes,
    Vlad
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  10. Dean Wyant
    Dean Wyant avatar
    46 posts
    Member since:
    Nov 2009

    Posted 11 May 2011 Link to this post

    Here you go - an EmptyDataTemplate Attached property.  (The blog posts a behavior)

    I needed to set the template from code behind and I thought it would be great to have it be an Attached Property.
    As discussed in http://www.telerik.com/help/silverlight/radtabcontrol-item-templates-and-selectors.html and other topics, a DataTemplate property can be set in code, from a Resource and using Style / Setter.

    I added a default template so you can just set EmptyText="Your Text." if you do not need your own template.

    To access the properties in your xaml, do not forget to add the reference - something like this
        xmlns:gvp="clr-namespace:Telerik.Windows.Controls.GridView;assembly=MyAssembly"
    
    Then you can do this:
        <telerik:RadGridView ... gvp:RadGridViewProperties.EmptyText="No Matching Data."...
    Or you can make your own template in a resource like so:

      <telerik:RadGridView ... gvp:RadGridViewProperties.EmptyDataTemplate="{StaticResource MyEmptyDataTemplate}">
    
      
    <UserControl.Resources>     <DataTemplate x:Key="MyEmptyDataTemplate" >       <TextBlock Text="Custom Empty Data Template" HorizontalAlignment="Center"  VerticalAlignment="Center" />     </DataTemplate>      </UserControl.Resources>

    I have not tried to set it in a Style, but I believe the syntax would be:

           <Style TargetType="telerik:RadGridView">
               
    <Setter Property="gvp:RadGridViewProperties.EmptyDataTemplate">
                   
    <Setter.Value>
                      <DataTemplate>
                          <TextBlock Text="Custom Empty Data Template" HorizontalAlignment="Center"  VerticalAlignment="Center" />
                      </DataTemplate>   
                   </Setter.Value>
               
    </Setter>
           
    </Style>

    In code behind:
    RadGridViewProperties.SetEmptyText(grid, "No Matching Data.");
    RadGridViewProperties.SetEmptyDataTemplate(grid, MyEmptyDataTemplate);
    

    RadGridViewProperties.cs

    using System;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Markup;
    using System.Collections;
    using Telerik.Windows.Data;
      
    namespace Telerik.Windows.Controls.GridView
    {
      public class RadGridViewProperties
      {
        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        #region EmptyDataTemplateHandler
      
        internal class EmptyDataTemplateHandler
        {
          private RadGridView _grid;
          private ContentPresenter _contentPresenter;
      
          internal EmptyDataTemplateHandler(RadGridView grid)
          {
            _grid = grid;
            Grid rootGrid = _grid.ChildrenOfType<Grid>().FirstOrDefault();
            if (rootGrid != null)
            {
              LoadContentPresenter(rootGrid);
              _grid.Items.CollectionChanged -= OnGridCollectionChanged;
              _grid.Items.CollectionChanged += OnGridCollectionChanged;
              SetVisibility();
            }
          }
      
          internal void Unhook()
          {
            _grid.Items.CollectionChanged -= OnGridCollectionChanged;
          }
      
          private void OnGridCollectionChanged(object sender, 
            System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
          {
            SetVisibility();
          }
      
          private void LoadContentPresenter(Grid rootGrid)
          {
            _contentPresenter = new ContentPresenter();
            _contentPresenter.IsHitTestVisible = false;
            _contentPresenter.SetValue(Grid.RowProperty, 2);
            _contentPresenter.SetValue(Grid.RowSpanProperty, 2);
            _contentPresenter.SetValue(Grid.ColumnSpanProperty, 2);
            _contentPresenter.SetValue(Border.MarginProperty, new Thickness(0, 27, 0, 0));
              rootGrid.Children.Add(_contentPresenter);
          }
      
          private void SetVisibility()
          {
            if (_grid != null)
            {
              if (_contentPresenter != null)
              {
                if (_grid.Items.Count == 0)
                {
                  LoadEmptyDataTemplate(); // Always load because it may be changed at any time
                  _contentPresenter.Visibility = Visibility.Visible;
                }
                else
                  _contentPresenter.Visibility = Visibility.Collapsed;
              }
            }
          }
      
          private void LoadEmptyDataTemplate()
          {
            var template = GetEmptyDataTemplate(_grid);
            if (template == null)
              template = GetDefaultTemplate();
            _contentPresenter.ContentTemplate = template;
          }
      
          private DataTemplate GetDefaultTemplate()
          {
            string text = GetEmptyText(_grid);
            if (String.IsNullOrEmpty(text))
              text = "No Matching Records Found.";
      
            var template = XamlReader.Load(String.Format(
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
       <TextBlock Text=""{0}"" HorizontalAlignment=""Center""  VerticalAlignment=""Center"" />
    </DataTemplate>", text));
            return (DataTemplate)template;
          }
        }
        #endregion EmptyDataTemplateHandler
        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
      
        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        #region EmptyDataTemplate and EmptyText
      
        /// <summary>
        /// The template to use when there is no data to display in the grid
        /// When not set and EmptyText is set, a default template is used
        /// </summary>
        /// <see cref="EmptyTextProperty"/>
        public static readonly DependencyProperty EmptyDataTemplateProperty =
          DependencyProperty.RegisterAttached("EmptyDataTemplate", typeof(DataTemplate), 
          typeof(RadGridView), new PropertyMetadata(OnEmptyDataTemplateChanged));
      
        #region Accessors
        /// <summary>
        /// The template to use when there is no data to display in the grid
        /// When not set and EmptyText is set, a default template is used
        /// </summary>
        /// <see cref="EmptyTextProperty"/>
        public static DataTemplate GetEmptyDataTemplate(DependencyObject obj)
        {
          return (DataTemplate)obj.GetValue(EmptyDataTemplateProperty);
        }
      
        /// <summary>
        /// The template to use when there is no data to display in the grid
        /// When not set and EmptyText is set, a default template is used
        /// </summary>
        /// <see cref="EmptyTextProperty"/>
        public static void SetEmptyDataTemplate(DependencyObject obj, DataTemplate value)
        {
          obj.SetValue(EmptyDataTemplateProperty, value);
        }
        #endregion Accessors
      
        /// <summary>
        /// The text to show when using the default EmptyDataTemplate.
        /// Default text = "No Matching Records Found."
        /// If EmptyDataTemplate is set, EmptyText is not used.
        /// <see cref="EmptyDataTemplateProperty"/>
        /// </summary>
        public static readonly DependencyProperty EmptyTextProperty =
          DependencyProperty.RegisterAttached("EmptyText", typeof(string), 
          typeof(RadGridView), new PropertyMetadata(OnEmptyTextChanged));
      
        #region Accessors
        /// <summary>
        /// The text to show when using the default EmptyDataTemplate.
        /// Default text = "No Matching Records Found."
        /// If EmptyDataTemplate is set, EmptyText is not used.
        /// <see cref="EmptyDataTemplateProperty"/>
        /// </summary>
        public static string GetEmptyText(DependencyObject obj)
        {
          return (string)obj.GetValue(EmptyTextProperty);
        }
      
        /// <summary>
        /// The text to show when using the default EmptyDataTemplate.
        /// Default text = "No Matching Records Found."
        /// If EmptyDataTemplate is set, EmptyText is not used.
        /// <see cref="EmptyDataTemplateProperty"/>
        /// </summary>
        public static void SetEmptyText(DependencyObject obj, string value)
        {
          obj.SetValue(EmptyTextProperty, value);
        }
        #endregion Accessors
      
        #region EventHandlers
        private static void OnEmptyDataTemplateChanged(DependencyObject d, 
          DependencyPropertyChangedEventArgs e)
        {
          var grid = d as RadGridView;
          if (grid != null)
          {
            if (e.NewValue == null)
              UnhookEmptyDataTemplate(grid);
            else
              HookEmptyDataTemplate(grid);
          }
        }
      
        private static void OnEmptyTextChanged(DependencyObject d, 
          DependencyPropertyChangedEventArgs e)
        
          var grid = d as RadGridView;
          if (grid != null)
          {
            if (String.IsNullOrEmpty((String)e.NewValue))
              UnhookEmptyDataTemplate(grid);
            else
              HookEmptyDataTemplate(grid);
          }
        }
      
        private static void OnEmptyDataTemplateGridLoaded(object sender, EventArgs e)
        {
          if (InitEmptyDataTemplate(sender))
            ((RadGridView)sender).Loaded -= OnEmptyDataTemplateGridLoaded;
        }
      
        private static void OnEmptyDataTemplateGridDataLoaded(object sender, EventArgs e)
        {
          if (InitEmptyDataTemplate(sender))
            ((RadGridView)sender).DataLoaded -= OnEmptyDataTemplateGridDataLoaded;
        }
      
        #endregion EventHandlers
      
        #region Implementation
        /// <summary>
        /// The ContentPresenter to used to hold the EmptyDataTemplate
        /// This is used internally to store/retrieve the ContentPresenter
        /// </summary>
        internal static readonly DependencyProperty EmptyDataTemplateHandlerProperty =
          DependencyProperty.RegisterAttached("EmptyDataTemplateHandler"
          typeof(EmptyDataTemplateHandler), typeof(RadGridView), null);
      
        #region Accessors
        internal static EmptyDataTemplateHandler GetEmptyDataTemplateHandler(DependencyObject obj)
        {
          return (EmptyDataTemplateHandler)obj.GetValue(EmptyDataTemplateHandlerProperty);
        }
      
        internal static void SetEmptyDataTemplateHandler(DependencyObject obj, 
          EmptyDataTemplateHandler value)
        {
          EmptyDataTemplateHandler handler = GetEmptyDataTemplateHandler(obj);
          if (handler != null)
            handler.Unhook();
          obj.SetValue(EmptyDataTemplateHandlerProperty, value);
        }
        #endregion Accessors
      
        private static bool InitEmptyDataTemplate(object sender)
        {
          var grid = sender as RadGridView;
          if (grid != null)
          {
            EmptyDataTemplateHandler handler = new EmptyDataTemplateHandler(grid);
            return true;
          }
          return false;
        }
      
      
        private static void HookEmptyDataTemplate(RadGridView grid)
        { // Attach to Loaded, which will attach to CollectionChanged
          UnhookEmptyDataTemplate(grid); // It does not hurt to unhook before hooking
          grid.Loaded += OnEmptyDataTemplateGridLoaded;
          grid.DataLoaded += OnEmptyDataTemplateGridDataLoaded;
        }
      
        private static void UnhookEmptyDataTemplate(RadGridView grid)
        { // Make sure events are no longer attached
          grid.Loaded -= OnEmptyDataTemplateGridLoaded;
          grid.DataLoaded -= OnEmptyDataTemplateGridDataLoaded;
          SetEmptyDataTemplateHandler(grid, null);
        }
      
        #endregion Implementation
      
        #endregion EmptyDataTemplate and EmptyDataText
        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
      
      } // RadGridViewProperties
      
    }
  11. Brian Sayatovic
    Brian Sayatovic avatar
    91 posts
    Member since:
    Nov 2009

    Posted 24 May 2011 Link to this post

    I tried the original behavior and couldn't get it it work.  Then I tried the attached property one and it works! ...better.  But the empty template shows when there isn't any data AND when there IS data.

    My ItemsSource is bound to an ObservableCollection.  My code clears and populates that ObservableCollection when someone changes a dropdown.  My breakpoint inside EmptyDataTemplateSetVisibility is never reached because 'grid' is null.  Up the stack, the 'sender' of the event isn't the RadgridView but a Telerik.Windows.Data.DataItemCollection.
  12. Dean Wyant
    Dean Wyant avatar
    46 posts
    Member since:
    Nov 2009

    Posted 24 May 2011 Link to this post

    OK, if you are using the property, which property are you using: EmptyText or EmptyDataTemplate?
    Is it set in xaml or code?
    Please paste it so I can see.

    The properties are not in the EmptyDataTemplate class, they are statics in RadGridViewProperties.
    The EmptyDataTemplate class is for attaching in code without using behaviours - it is not set by properties.

    The properties should be much better and they work like so:
    According to which property is set, OnEmptyDataTemplateChanged or OnEmptyTextChanged should be called. Within that method, "grid" is the "DependencyObject" passed so it should not be null. If the DependencyObject is a "DataItemCollection", then the property is being set for the wrong object.

    If you are using the EmptyDataTemplate class (as it sounds like you are), then you have to set it in code like so:

    Somewhere in your code:
            EmptyDataTemplateBehavior EDTB = new EmptyDataTemplateBehavior(grid);

    Or:
            EmptyDataTemplateBehavior EDTB = new EmptyDataTemplateBehavior();
    EDTB.Attach(grid);

    The _grid var will be set directly from what you pass, so it should not be null.

    I imagine that your problem may be something I do not see. More details would be needed to track it down.

  13. Dean Wyant
    Dean Wyant avatar
    46 posts
    Member since:
    Nov 2009

    Posted 24 May 2011 Link to this post

    Never mind, I see the bug. I am looking into it.
    Thanks.
  14. Brian Sayatovic
    Brian Sayatovic avatar
    91 posts
    Member since:
    Nov 2009

    Posted 24 May 2011 Link to this post

    Hey, no problem.  I appreciate your help!

    As far as I can tell, when the collection changes, the sender isn't the RadGridView but the data collection.  I looked but didn't find a way back to the owning RadGridView from the data collection sender.  I was considering tinkering by using a closure around the grid when attaching the event handlers.
  15. Dean Wyant
    Dean Wyant avatar
    46 posts
    Member since:
    Nov 2009

    Posted 24 May 2011 Link to this post

    I updated the post with the new code. I used a class as a dependency property to hold the grid instance and some of the underlying code.
    I do not know how to use a closure in this instance. Perhaps the code using a closure would be better?
    I kind of like the code with the class because it gets rid of a bunch of static methods.

    I hope this version is bug free... no dangling event handlers, etc. .... no guarantees :-)
    This was put together pretty hastily, so if anyone has bugs, improvements, please post them.
    Thanks.
  16. Brian Sayatovic
    Brian Sayatovic avatar
    91 posts
    Member since:
    Nov 2009

    Posted 25 May 2011 Link to this post

    This is working great for me.  FWIW, I think closures would've had the same opportunity for memory leaks as the class-based approach you've used.  I think your class-based approach is more understandable though.

    Thank you for sharing this with the community?
  17. Brian Sayatovic
    Brian Sayatovic avatar
    91 posts
    Member since:
    Nov 2009

    Posted 25 May 2011 Link to this post

    Pavel Pavlov said in April 2009 that this was being scheduled for the [2009] Q2 release:

    "Unfortunately we are missing that feature. I have already talked to my team and we have decided to schedule this  for the Q2 release."

    Whatever happened to that?
  18. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 11 Aug 2011 Link to this post

    Having trouble with this attached property. Trying to add this to my WPF RadGridView, but when I copied the code I get an error at the XamlReader.Load method. saying "unknown method Load(string).

    How do I fix this so that it works? Thanks for the work on this.
  19. Dean Wyant
    Dean Wyant avatar
    46 posts
    Member since:
    Nov 2009

    Posted 11 Aug 2011 Link to this post

    I think WPF XamlReader.Parse(string) is the equivalent of Silverlight XamlReader.Load(string).

    This was done for the Silverlight control. So, it may need changes for WPF.
    I do not know.

  20. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 11 Aug 2011 Link to this post

    Thanks. That worked.
  21. Robert
    Robert avatar
    6 posts
    Member since:
    May 2011

    Posted 16 Sep 2011 Link to this post

    Again, what happend to this?

    Pavel Pavlov said in April 2009 that this was being scheduled for the [2009] Q2 release:

    "Unfortunately we are missing that feature. I have already talked to my team and we have decided to schedule this  for the Q2 release."
  22. UGH!!
    UGH!! avatar
    21 posts
    Member since:
    Nov 2010

    Posted 20 Sep 2011 Link to this post

    This feature would be nice to have!!
  23. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 04 Oct 2011 Link to this post

    Hi,
    The problem I have with that behavior is that the line 

    Grid rootGrid = gridView.ChildrenOfType<Grid>().FirstOrDefault();

    does never return anything... I can see in the control tree using silverlight spy that some grid controls are present in the childrens but the method never returns anything. I tried other types two. Using the latest version 920...

    any hints on that?
    thanks,
    John.
  24. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 05 Oct 2011 Link to this post

    Hello John,

    Would you clarify what is the exact structure of your application ? Do you define RadGridView in a RadTabControl or any other element ?
     

    Best wishes,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  25. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 05 Oct 2011 Link to this post

    Hi Maya,
    Thank you very much for looking into this...

    This is what I have...

    <UserControl x:Class="SoPratic.SL.Views.CommandesPage">
        <UserControl.Resources>
            <app:CommandesViewModel x:Key="commandesVM"/>
            <ctls:CommandGridStyleSelector x:Key="CellStyleSelector" />
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" DataContext="{StaticResource commandesVM}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="400*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <sdk:Label Grid.Row="0" Content="{Binding CommandDescription, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Center" Name="lblOrder" Margin="5,0,0,0" />
            <telerik:RadBusyIndicator Grid.Row="1" Name="busyIndicator" IsBusy="{Binding IsBusy}"
                                BusyContent="Veuillez patienter..." >
                <telerik:RadGridView Name="grdBeneficiaire" IsReadOnly="False" AutoGenerateColumns="False" ShowInsertRow="False"
                                     ItemsSource="{Binding View}" ShowGroupFooters="True" ShowColumnFooters="True" ElementExporting="grdBeneficiaire_ElementExporting"
                                     CanUserInsertRows="False" CanUserDeleteRows="False" RowStyleSelector="{StaticResource CellStyleSelector}"
                                     ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
                    <i:Interaction.Behaviors>
                        <app:EmptyDataTemplateBehavior>
                            <app:EmptyDataTemplateBehavior.EmptyDataTemplate>
                                <DataTemplate>
                                    <TextBlock Text="Aucune commande en cours de saisie." Foreground="Gray" HorizontalAlignment="Center"  VerticalAlignment="Center" />
                                </DataTemplate>
                            </app:EmptyDataTemplateBehavior.EmptyDataTemplate>
                        </app:EmptyDataTemplateBehavior>
                    </i:Interaction.Behaviors>
                    <telerik:RadGridView.GroupRowStyle >
                        <Style TargetType="telerik:GridViewGroupRow">
                            <Setter Property="ShowHeaderAggregates" Value="True" />
                        </Style>
                    </telerik:RadGridView.GroupRowStyle>
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn Header="OdlID" DataMemberBinding="{Binding OdlID}" UniqueName="OdlID" />

    And this is my EmptyDataTemplateBehavior:
    public class EmptyDataTemplateBehavior : Behavior<RadGridView>
        {
            ContentPresenter contentPresenter = new ContentPresenter();
     
            protected override void OnAttached()
            {
                base.OnAttached();
                this.AssociatedObject.LayoutUpdated += new EventHandler(AssociatedObject_LayoutUpdated);
            }
     
            public DataTemplate EmptyDataTemplate { get; set; }
     
            void AssociatedObject_LayoutUpdated(object sender, EventArgs e)
            {
                this.AssociatedObject.LayoutUpdated -= new EventHandler(AssociatedObject_LayoutUpdated);
                this.LoadTemplateIntoGridView(this.AssociatedObject);
                this.AssociatedObject.Items.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Items_CollectionChanged);
                SetVisibility();
            }
     
            void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            {
                SetVisibility();
            }
     
            private void SetVisibility()
            {
                if (this.AssociatedObject.Items.Count ==0)
                    this.contentPresenter.Visibility = Visibility.Visible;
                else
                    this.contentPresenter.Visibility = Visibility.Collapsed;
            }
     
            private void LoadTemplateIntoGridView(RadGridView gridView)
            {
                contentPresenter.IsHitTestVisible = false;
                contentPresenter.DataContext = this;
                contentPresenter.ContentTemplate = this.EmptyDataTemplate;
                 
                //TODO make this work
                Grid rootGrid = gridView.ChildrenOfType<Grid>().FirstOrDefault();
                if (rootGrid != null)
                {
                    contentPresenter.SetValue(Grid.RowProperty, 2);
                    contentPresenter.SetValue(Grid.RowSpanProperty, 2);
                    contentPresenter.SetValue(Grid.ColumnSpanProperty, 2);
                    contentPresenter.SetValue(Border.MarginProperty, new Thickness(0, 27, 0, 0));
     
                    rootGrid.Children.Add(contentPresenter);
                }
            }
        }

  26. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 05 Oct 2011 Link to this post

    Hi John,

    Would you try the following:
    1. Remove the line in the LayoutUpdated event:

    this.AssociatedObject.LayoutUpdated -= new EventHandler(AssociatedObject_LayoutUpdated);
     2. and place it here:
    private void LoadTemplateIntoGridView(RadGridView gridView)
            {
      
                contentPresenter.IsHitTestVisible = false;
                contentPresenter.DataContext = this;
                contentPresenter.ContentTemplate = EmptyDataTemplate;
      
                if (gridView.ChildrenOfType<Grid>().Count > 0)
                {
                    Grid rootGrid = gridView.ChildrenOfType<Grid>()[1];
                    contentPresenter.SetValue(Grid.RowProperty, 2);
                    contentPresenter.SetValue(Grid.RowSpanProperty, 2);
                    contentPresenter.SetValue(Grid.ColumnSpanProperty, 2);
                    contentPresenter.SetValue(FrameworkElement.MarginProperty, new Thickness(0, 27, 0, 0));
                    rootGrid.Children.Add(contentPresenter);
                    this.AssociatedObject.LayoutUpdated -= new EventHandler(AssociatedObject_LayoutUpdated);
                }
            }

    Is that approach resolving the issue ? 

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  27. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 05 Oct 2011 Link to this post

    Excellent!
    Yes, indeed it works... Very good job...

    I double checked here:
    http://blogs.telerik.com/blogs/posts/10-02-01/empty_data_template_in_radgridview_for_silverlight_and_wpf.aspx
    and the event is not removed, that's why it's working.
    I don't know where taht line comes from.

    Certainely my bad.

    Thanks a lot Maya, I would have been unable to solve this by myself.

    John.
  28. sandy
    sandy avatar
    23 posts
    Member since:
    Aug 2010

    Posted 27 Jan 2012 Link to this post

    Excellent.
    this code is really helped me a lot for applying emptydatatemplete to multiple radgridview's.
  29. ATeam
    ATeam avatar
    24 posts
    Member since:
    Jan 2010

    Posted 27 Jun 2012 Link to this post

    Hello!

    I've tried the EmptyDataTemplate and also midified it but in our scenario it didn't work as expected.

    The content of the ContentPresenter, in my case a textblock will not be shown. But if i use a Spy-Tool i see that it is in the rootGrid Container but it seems that it is behind the GridViewVirtualizingPanel.

    Is there any chance to bring the EmptyDataTemplate in front of it?

    //Update: Setting the foreground property not equal to the background property helps ;-)
  30. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 27 Jun 2012 Link to this post

    Hi Dominik,

    Can you try changing the foreground of the TextBlock ? Do you still not see the text ? Could you clarify which version of RadControls you work with ?  

    All the best,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  31. Witt
    Witt avatar
    7 posts
    Member since:
    Mar 2015

    Posted 30 Apr 2015 Link to this post

    Hi,

    I've tried changing this line :

    <TextBlock Text="Aucune commande en cours de saisie."Foreground="Gray" HorizontalAlignment="Center"  VerticalAlignment="Center" />
    <TextBlock Text="Aucune commande en cours de saisie."Foreground="Gray" HorizontalAlignment="Center"  VerticalAlignment="Center" />

    to :

    <TextBlock Text="{Binding EmptyText}"Foreground="Gray" HorizontalAlignment="Center"  VerticalAlignment="Center" />
    <TextBlock Text="{Binding EmptyText}"Foreground="Gray" HorizontalAlignment="Center"  VerticalAlignment="Center" />

     in order to change display text at runtime. I have create property EmptyText in ViewModel.cs as following :

     

     private string _emptyText;
            public string EmptyText
            {
                get
                {
                    return _emptyText;
                }
                set
                {
                    if (_emptyText != value)
                    {
                        _emptyText = value;
                        NotifyOfPropertyChange(() => EmptyText);
                    }
                }
            }

    The problem is the text doesn't show up. May I have any suggestion or a way to resolve this problem please?

    Thanks,
    Witt

Back to Top
DevCraft banner