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

GridViewCell ControlTemplate binding

3 Answers 247 Views
GridView
This is a migrated thread and some comments may be shown as answers.
masha reznik
Top achievements
Rank 1
masha reznik asked on 20 Apr 2010, 08:08 PM
Hello,
i have a controltemplate for GridViewCell and I'm having some problems with its binding.
First of all when i used: (the column is binded to Price)
Text="{Binding Path=Content.Field.Value}" 
The value disapears from the cell when the row is selected.

Then i tried:
Text="{Binding Path=DataContext.Price, Mode=TwoWay, Converter = {StaticResource CentPriceConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewRow}}}" 
but this way the value in the source object  is not updated. the setter is called with the old value

can you tell what I'm doing wrong?

my controlTemplate looks like this:
                <ControlTemplate x:Key="PriceExpandedCell" TargetType="telerik:GridViewCell">  
                    <Border Name="Part_Border"   
                            CornerRadius="0"   
                            Loaded="Part_Border_Loaded" 
                            Height="Auto" 
                            BorderBrush="{StaticResource SolidBorderBrush}" 
                            VerticalAlignment="Stretch">  
                        <StackPanel Name="Part_StackPanel"   
                                    ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                                    Orientation="Vertical" 
                                    Background="{Binding Path=Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewRow}}}">  
                            <TextBox Name="Part_Text"    
                                     Width="Auto"   
                                     BorderThickness="0" 
                                     Background="Transparent" 
                                     Margin="2,2,2,2"   
                                     TextChanged="Part_Text_TextChanged" 
                                     Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewRow}}}" 
                                     Text="{Binding Path=DataContext.Price, Mode=TwoWayConverter = {StaticResource CentPriceConverter},   
                                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewRow}}}"/> 
                            <Button Content="Discount" Margin="15,3,3,3"   
                                    Name="btnDiscount" 
                                    Click="btnDiscount_Click" 
                                    HorizontalAlignment="Left" 
                                    Style="{StaticResource CompactButton}"/>  
                        </StackPanel> 
                    </Border> 
                    <ControlTemplate.Triggers> 
                        <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewRow}}}" Value="True">  
                            <Setter TargetName="Part_StackPanel" Property="Background" Value="{StaticResource HighlightGradientBrush}"/>  
                        </DataTrigger> 
                        <Trigger Property="IsInEditMode" Value="True">  
                            <Setter TargetName="Part_Border" Property="BorderThickness" Value="3"/>  
                            <Setter TargetName="Part_StackPanel" Property="Background" Value="{StaticResource LightBlueBrush}"/>  
                        </Trigger> 
 
                    </ControlTemplate.Triggers> 
                </ControlTemplate> 
 

Thanks!

3 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 23 Apr 2010, 09:42 AM
Hi masha,

Looking at your sample XAML code I'm not sure why you are experiencing these issues. Can you please open a support ticket and attach a sample project illustrating your issue exactly?

Also why are you not using a DataTemplate as a CellTemplate in the column? I think you don't need a custom cell style in your scenario.

All the best,
Stefan Dobrev
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
R
Top achievements
Rank 1
answered on 12 Dec 2014, 05:50 AM
HI,

I want to show decimal no. in a gridviewcell with digits after decimal in bigger font. can you show me a sample xaml for the same? I am able to change gridviewrow appearance but this particular cell templating is not working as expected. attached image shows the UI i want using Telerik GridView.

Regards,

Rishi
0
Dimitrina
Telerik team
answered on 16 Dec 2014, 09:40 AM
Hello,

GridViewCells do not offer such functionality by default, and that comes from the current WPF implementation Microsoft offers. Nevertheless, the GridView suggests a way to set anything you want as a content to the cells via DataTemplates. This help article explains how to set CellTemplate/CellEditTemplate in details.

This is a very detailed blog about how you can write a simple Highlighting TextBlock, that can be tweaked to show Bolded Runs. When the HiglightingTextBlock is given some text, it is broken down to different Runs in order to only highlight some of them, which gives the impression of highlighting some characters in the text shown in the TextBlock. You can use this control as a cell template, in order to achieve a custom formatting you desire. 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
masha reznik
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
R
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or