ControlTemplate for GridViewCell

9 posts, 1 answers
  1. John
    John avatar
    19 posts
    Member since:
    May 2009

    Posted 16 Jul 2009 Link to this post

    Greetings,

    I am trying to create a ControlTemplate for a GridViewCell. The only real change in my template is the addition of another component - a status indicator (PropertyStatus) that will be placed in each cell. I am trying to position the status indicator directly to the right of the cell's AlignmentContentPresenter...To keep things simple, here is the relevant snippet from the control template I am trying to create:

    <StackPanel Orientation="Horizontal"
                        <Telerik_Windows_Controls_GridView:AlignmentContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="3,33.5,2,0" x:Name="PART_ContentPresenter" VerticalAlignment="Top" Visibility="Visible" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" TextAlignment="{TemplateBinding TextAlignment}" TextDecorations="{TemplateBinding TextDecorations}" TextWrapping="{TemplateBinding TextWrapping}"/>

                        <csla:PropertyStatus Property="{TemplateBinding Column.UniqueName}" Source="{Binding}"/> 
    </StackPanel> 

    So, if you haven't already noticed, the PropertyStatus control needs to be able to set a property named Property which is the name (string) of the column's bound property name. To gain access to the name of the bound property in C#, one would do something like "GridViewCell.Column.UniqueName". Make sense? Without much confidence, in the control template above, I tried Property="{TemplateBinding Column.UniqueName}" which failed to work.

    Two questions:

    (1) Any thoughts on how i could  access the cell's column's unique name from the control template and use it to set the Property property on my PropertyStatus control?

    (2) In my cell's template i see a ContentPresenter and an AlignmentContentPresenter. Can you explain the difference and when each are used? I want to make sure that i am positioning my component next to the appropriate ContentPresenter.

    Thanks a bunch!
  2. John
    John avatar
    19 posts
    Member since:
    May 2009

    Posted 17 Jul 2009 Link to this post

    After a bit more research, I think that using DataTemplates instead of ControlTemplates might be the way to go... However, I don't think this change solves my problem above. I will continue investigating...
  3. Answer
    Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 21 Jul 2009 Link to this post

    Hello John,

    Please find attached a sample application (SL3) which handles your scenario. As the Column is not a DependencyObject you cannot perform TemplateBinding and that is the reason your binding fails. Another thing I am sure you will notice that RelativeSource is being used which is available only in SL3.

    As for the two content presenters: AlignmentContentPresenter is used for displaying the Data in the grid. You have correctly places your PropertyStatus control in the StackPanel. The other presenter is used to load the proper editors when the cell enters edit mode.

    Best wishes,
    Kalin Milanov
    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.
  4. John
    John avatar
    19 posts
    Member since:
    May 2009

    Posted 15 Sep 2009 Link to this post

    Sorry for the very (very) delayed response. We just now upgraded to SL3. I tried your example, and it works great with one exception. When you enter edit mode in a cell for 'Property1', is there any way to change the TextBlock's Visibility to Collapsed? It remains visible during edit mode and jumbles the text.

    Thanks for your help!
  5. John
    John avatar
    19 posts
    Member since:
    May 2009

    Posted 15 Sep 2009 Link to this post

    Actually, this was quite simple. I was able to leverage the BeginningEdit and CellEditEnded events and use the cell's ChildrenOfType extension method to locate the PropertyStatusControl and hide/show it respectively.

    Thanks.
  6. Christian
    Christian avatar
    52 posts
    Member since:
    Apr 2011

    Posted 14 Nov 2011 Link to this post

    Can you please tell me where I can find AlignmentContentPresenter?
    Has it been replaced/removed?
    When I include

    xmlns:grid="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"

    like I saw in several examples here on the forum the AlignmentContentPresenter can still not be found

  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Nov 2011 Link to this post

    Hello,

     This class was removed back in Q3 2009 (you can check the release notes). Please copy our latest templates using Blend. 

    All the best,
    Vlad
    the Telerik team

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

  8. Christian
    Christian avatar
    52 posts
    Member since:
    Apr 2011

    Posted 14 Nov 2011 Link to this post

    Blend only allows me to copy the standard theme, but I need the template for GridViewHeaderCell for SummerTheme.
    Could you please attach it?
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Nov 2011 Link to this post

    Hello,

     You can get it from:

    C:\Program Files (x86)\Telerik\RadControls for Silverlight Q2 2011\Themes

    Best wishes,
    Vlad
    the Telerik team

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

Back to Top