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

[Solved] Property paths

1 Answer 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jon Bergquist
Top achievements
Rank 1
Jon Bergquist asked on 03 Apr 2009, 07:22 PM
I have a cellstyle defined as defined below:

 <Style x:Key="DayViewCellStyle1" TargetType="gridview:GridViewCell"
            <Setter Property="Template"
                <Setter.Value> 
                   <ControlTemplate TargetType="gridview:GridViewCell"
                        <Border x:Name="GridViewCellBorder" 
                                    
                                    BorderThickness="{TemplateBinding BorderThickness}"  
                                    BorderBrush="{TemplateBinding BorderBrush}"  
                                    Background="{TemplateBinding Background}"
                       
                            <Grid x:Name="GridViewCellGrid"
                                <gridview:AlignmentContentPresenter x:Name="PART_ContentPresenter" TextAlignment="Center" Margin="{TemplateBinding Padding}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Visibility="Collapsed"/> 
                                <StackPanel Orientation="Vertical" Margin="3"
                                    <TextBlock Text="{Binding Slot2.CustomerName}"></TextBlock> 
                                    <TextBlock Text="{Binding Slot2.CaseId}"></TextBlock> 
                                    <TextBlock Text="{Binding Slot2.ProblemCategory}"></TextBlock> 
                                    <TextBlock Text="{Binding Slot2.CustomerName}"></TextBlock> 
                                </StackPanel> 
                                <Rectangle Width="{TemplateBinding VerticalLineThickness}" Fill="{TemplateBinding VerticalLineFill}" HorizontalAlignment="Right" Visibility="{TemplateBinding VerticalLineVisibility}"/> 
                                <Rectangle Width="Auto" Height="Auto" x:Name="therect" Margin="0" Visibility="Collapsed" Stroke="#FFFFAB3F" StrokeThickness="2" /> 
                                <Rectangle Width="Auto" Height="Auto" x:Name="CurrentBorder" Margin="2" Visibility="Collapsed" Stroke="#FF000000" StrokeThickness="1" StrokeDashOffset="0" StrokeDashCap="Square" StrokeDashArray="2"/> 
                            </Grid> 
                            <VisualStateManager.VisualStateGroups> 
                                <VisualStateGroup x:Name="EditingStates"
 
                                    <VisualState x:Name="Normal"
                                        <Storyboard> 
 
                                            <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" 
                                                           Storyboard.TargetProperty="Visibility"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible" /> 
                                            </ObjectAnimationUsingKeyFrames>--> 
 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="therect" 
                                                           Storyboard.TargetProperty="Visibility"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed" /> 
                                            </ObjectAnimationUsingKeyFrames> 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" 
                                                           Storyboard.TargetProperty="Visibility"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed" /> 
                                            </ObjectAnimationUsingKeyFrames> 
 
                                        </Storyboard> 
                                    </VisualState> 
                                    <VisualState x:Name="Current"
                                        <Storyboard> 
 
                                            <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" 
                                                           Storyboard.TargetProperty="Visibility"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible" /> 
                                            </ObjectAnimationUsingKeyFrames>--> 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="therect" 
                                                           Storyboard.TargetProperty="Visibility"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed" /> 
                                            </ObjectAnimationUsingKeyFrames> 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" 
                                                           Storyboard.TargetProperty="Visibility"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed" /> 
                                            </ObjectAnimationUsingKeyFrames> 
                                            <!--Cell background is set to orange when a cell is current--> 
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewCellBorder" 
                                                           Storyboard.TargetProperty="Background"
                                                <DiscreteObjectKeyFrame KeyTime="0:0:0" > 
                                                    <DiscreteObjectKeyFrame.Value> 
                                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"
                                                            <GradientStop Color="#FFFFD9AA" Offset="1"/> 
                                                            <GradientStop Color="#FFFFAB3F" Offset="0"/> 
                                                        </LinearGradientBrush> 
                                                    </DiscreteObjectKeyFrame.Value> 
                                                </DiscreteObjectKeyFrame> 
                                            </ObjectAnimationUsingKeyFrames> 
                                        </Storyboard> 
                                    </VisualState> 
                                </VisualStateGroup> 
                            </VisualStateManager.VisualStateGroups> 
                        </Border> 
                    </ControlTemplate>                       
                </Setter.Value> 
            </Setter> 
        </Style> 

However, you notice it is using an object called "Slot2" to bind.  Since I need to do this for 5 additional columns (Slot1, Slot2, Slot3, Slot4, Slot5) I don't want to recreate this cellstyle every time just to set the Binding.  Every column will be bound to the same nested fields but the Object names will be different.  Any suggestions?

Thanks

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 06 Apr 2009, 12:40 PM
Hi Jon,

You can solve this by setting DataContext to any object that is parent for your textbox elements to the GridViewCell.Value property. Xaml code should look like this:

<Style x:Key="DayViewCellStyle1" TargetType="gridview:GridViewCell"
                <Setter Property="Template"
                    <Setter.Value> 
                        <ControlTemplate TargetType="gridview:GridViewCell"
                            <Border x:Name="GridViewCellBorder" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"
 
                                <Grid x:Name="GridViewCellGrid" DataContext="{TemplateBinding Value}"
                                    <gridview:AlignmentContentPresenter x:Name="PART_ContentPresenter" TextAlignment="Center" Margin="{TemplateBinding Padding}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Visibility="Collapsed" /> 
                                    <StackPanel Orientation="Vertical" Margin="3"
                                        <TextBlock Text="{Binding FirstName}"></TextBlock> 
                                        <TextBlock Text="{Binding MiddleName}"></TextBlock> 
                                        <TextBlock Text="{Binding LastName}"></TextBlock> 
                                    </StackPanel> 
                                    <Rectangle Width="{TemplateBinding VerticalLineThickness}" Fill="{TemplateBinding VerticalLineFill}" HorizontalAlignment="Right" Visibility="{TemplateBinding VerticalLineVisibility}" /> 
                                    <Rectangle Width="Auto" Height="Auto" x:Name="therect" Margin="0" Visibility="Collapsed" Stroke="#FFFFAB3F" StrokeThickness="2" /> 
                                    <Rectangle Width="Auto" Height="Auto" x:Name="CurrentBorder" Margin="2" Visibility="Collapsed" Stroke="#FF000000" StrokeThickness="1" StrokeDashOffset="0" StrokeDashCap="Square" StrokeDashArray="2" /> 
                                </Grid> 
... 


I'm also attaching a running sample application for your reference.

Greetings,
Nedyalko Nikolov
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Jon Bergquist
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or