GridViewCell ControlTemplate binding

4 posts, 0 answers
  1. masha reznik
    masha  reznik avatar
    17 posts
    Member since:
    Jan 2010

    Posted 20 Apr 2010 Link to this post

    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!

  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 23 Apr 2010 Link to this post

    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.
  3. R
    R avatar
    5 posts
    Member since:
    Sep 2013

    Posted 11 Dec 2014 in reply to Stefan Dobrev Link to this post

    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
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 Dec 2014 Link to this post

    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.

     
Back to Top