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

ControlTemplate for GridViewCell

8 Answers 135 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 16 Jul 2009, 06:33 PM
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!

8 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 17 Jul 2009, 12:37 PM
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...
0
Accepted
Kalin Milanov
Telerik team
answered on 21 Jul 2009, 04:12 PM
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.
0
John
Top achievements
Rank 1
answered on 15 Sep 2009, 09:50 PM
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!
0
John
Top achievements
Rank 1
answered on 16 Sep 2009, 01:08 AM
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.
0
Christian
Top achievements
Rank 1
answered on 14 Nov 2011, 03:25 PM
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

0
Vlad
Telerik team
answered on 14 Nov 2011, 03:32 PM
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 >>

0
Christian
Top achievements
Rank 1
answered on 14 Nov 2011, 03:37 PM
Blend only allows me to copy the standard theme, but I need the template for GridViewHeaderCell for SummerTheme.
Could you please attach it?
0
Vlad
Telerik team
answered on 14 Nov 2011, 03:47 PM
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 >>

Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Kalin Milanov
Telerik team
Christian
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or