Rad Event problem

6 posts, 0 answers
  1. Dario
    Dario  avatar
    29 posts
    Member since:
    Mar 2009

    Posted 18 Aug 2009 Link to this post

    Hi, 
    I am new to routed events, and I have some trouble understanding the whole registering to event  thing...
    As I understand it, when I use the bubble strategy: "The routed event then routes to successive parent elements until reaching the element tree root." as stated on Microsoft's site.
    My scenario is next:
    I have a custom column in RadGridView. In that column I have a custom header template, and in that template i have the custom textbox. In my textbox, I have implemented the Telerik.Windows.RoutedEvent called "KeyDown" with a bubbling strategy. So I have, lets say 10 columns, and every column has its textbox in a header.
    When I instantiate a column, I register it to my KeyDown event with Telerik's EventManager, thinking that inside my column, the textbox will fire KeyDown, and then it will be routed up to my column.
    My problem is next: All of my columns are catching the event from a textbox, so it is not just routed through the parents. 
    Is there a way to propagate the event only to a parent column?

  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 21 Aug 2009 Link to this post

    Hi Dario,

    Regarding your question are you setting the e.Handled = true when you receive the key down event. This will tell the eventing system to stop routing the event up the visual tree.

    As a general note GridView's columns are not part of the control's visual tree. The are just "definitions" what header cells will be created.

    Also looking at your scenario I think you can do without custom routed event. Are you using the column's Header property and define your TextBox or you are redefining the whole HeaderCellStyle? I think the Header property will do the work for you.

    All the best,
    Stefan Dobrev
    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.
  3. Dario
    Dario  avatar
    29 posts
    Member since:
    Mar 2009

    Posted 21 Aug 2009 Link to this post

    Hi Stefan,
    I am not sure what you mean when you say I can use only Header property. Can you give me an example how to do this?
    What I would like to achieve is to have a textbox in a column header, and to catch the KeyDown event (fired in textbox) in my custom column class.
    Tnx :)
  4. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Aug 2009 Link to this post

    Hi Dario ,

    Stefan meant that the Header property of our columns is of type object and you are allowed to place any kind of content there - you can even place a TextBox.

    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">  
        <telerik:GridViewDataColumn.Header> 
            <Border> 
                <TextBox KeyDown="TextBox_KeyDown"/>  
            </Border> 
    </telerik:GridViewDataColumn.Header> 

    The above XAML code will place a TextBox element in the column header and also subscribe to the KeyDown event. You could do the same for all of your columns and you should be able to implement the functionality and behaviour you desire.

    Regards,
    Milan
    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.
  5. Dario
    Dario  avatar
    29 posts
    Member since:
    Mar 2009

    Posted 24 Aug 2009 Link to this post

    Ah,
    But as I mentioned I'm using custom column implementation, so I am adding columns dynamically in code... :(
    So in code I am setting a template to my columns header:

    ColumnLayoutText  myCustomColumn = new ColumnLayoutText();
    myCustomColumn.HeaderCellStyle = (Style) this.Resources["headerCellWithCustomFilteringStyle"];


    And my header template is much bigger than just a textbox.. :( 
    Here it is:

           <Color x:Key="GridViewHeaderGradientColor1">#FFDFE2E5</Color>
            <Color x:Key="GridViewHeaderGradientColor2">#FFC7CBD1</Color>
            <Color x:Key="GridViewHeaderGradientColor3">#FFDBDEE1</Color>
            <Color x:Key="GridViewHeaderGradientColor4">#FFF8F8F9</Color>

            <Color x:Key="GridViewElementInnerBorderBrushColor">#FFEEEEEE</Color>

            <Color x:Key="GridViewHeaderCellForegroundColor">#FF000000</Color>

            <SolidColorBrush x:Key="GridViewHeaderCellMouseOverBorderBrush" Color="#FFFFFDE6" />

            <LinearGradientBrush x:Key="GridViewHeaderCellMouseOverBackground" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFFFE391" Offset="1" />
                <GradientStop Color="#FFFFFDEB" Offset="0" />
                <GradientStop Color="#FFFFD563" Offset="0.43" />
                <GradientStop Color="#FFFFEDB3" Offset="0.42" />
            </LinearGradientBrush>

            <LinearGradientBrush x:Key="GridViewHeaderCellSortedBackground" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFFCE79F" Offset="1" />
                <GradientStop Color="#FFFDD3A8" Offset="0.07" />
                <GradientStop Color="#FFF9932E" Offset="0.43" />
                <GradientStop Color="#FFFAAD5F" Offset="0.42" />
                <GradientStop Color="#FFB0987C" Offset="0" />
            </LinearGradientBrush>

            <Color x:Key="TransparentColor">Transparent</Color>

            <Color x:Key="GridViewIndicatorsPartsFillGradientStop1">#FF000000</Color>
            <Color x:Key="GridViewIndicatorsPartsFillGradientStop2">#FF000000</Color>

            <LinearGradientBrush x:Key="GridViewHeaderBackground" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="{StaticResource GridViewHeaderGradientColor4}" Offset="0" />
                <GradientStop Color="{StaticResource GridViewHeaderGradientColor3}" Offset="1" />
                <GradientStop Color="{StaticResource GridViewHeaderGradientColor1}" Offset="0.4" />
                <GradientStop Color="{StaticResource GridViewHeaderGradientColor2}" Offset="0.4" />
            </LinearGradientBrush>

            <SolidColorBrush x:Key="GridViewHeaderCellInnerBorderBrush" Color="{StaticResource GridViewElementInnerBorderBrushColor}" />

            <SolidColorBrush x:Key="GridViewHeaderCellForeground" Color="{StaticResource GridViewHeaderCellForegroundColor}" />

            <SolidColorBrush x:Key="GridViewHeaderCellSortingAndFilteringContentBackground" Color="{StaticResource TransparentColor}" />

            <LinearGradientBrush x:Key="GridViewIndicatorsPartsFill" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="{StaticResource GridViewIndicatorsPartsFillGradientStop1}" Offset="0" />
                <GradientStop Color="{StaticResource GridViewIndicatorsPartsFillGradientStop2}" Offset="1" />
            </LinearGradientBrush>

            <ControlTemplate x:Key="headerCellWithCustomFilteringTemplate" TargetType="gridView:GridViewHeaderCell">
                <Grid>
                    <Border x:Name="GridViewHeaderCell" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" UseLayoutRounding="True" />
                    <Border x:Name="GridViewHeaderCell_Over" BorderBrush="{StaticResource GridViewHeaderCellMouseOverBorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource GridViewHeaderCellMouseOverBackground}" Opacity="0" UseLayoutRounding="True" />
                    <Border x:Name="GridViewHeaderCell_Selected" BorderBrush="{StaticResource GridViewHeaderCellMouseOverBorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource GridViewHeaderCellSortedBackground}" Opacity="0" UseLayoutRounding="True" />

                    <Grid x:Name="PART_HeaderCellGrid">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="*"></RowDefinition>
                        </Grid.RowDefinitions>

                        <gridView:AlignmentContentPresenter Grid.Column="0" Grid.Row="0" Margin="3,4,2,3" VerticalAlignment="Center" TextAlignment="{TemplateBinding TextAlignment}" />

                        <Grid Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" Background="{StaticResource GridViewHeaderCellSortingAndFilteringContentBackground}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Path x:Name="PART_SortIndicator" Fill="{StaticResource GridViewIndicatorsPartsFill}" Stretch="Fill" Data="M0,0 L1,0 2,0 3,0 4,0 5,0 5,1 4,1 4,2 3,2 3,3 2,3 2,2 1,2 1,1 0,1 0,0 z" HorizontalAlignment="Left" Margin="1,0,4,0" VerticalAlignment="Center" Width="5" Height="3" RenderTransformOrigin="0.5,0.5">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1" ScaleY="-1" />
                                        <SkewTransform AngleX="0" AngleY="0" />
                                        <RotateTransform Angle="0" />
                                        <TranslateTransform X="0" Y="0" />
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                        </Grid>
                        <entities:HeaderTextBox x:Name="tbFilter" Grid.ColumnSpan="2" Grid.Column="0" Grid.Row="1"></entities:HeaderTextBox>
                    </Grid>

                    <VisualStateManager.VisualStateGroups>

                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal" />
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewHeaderCell_Over" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="1" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>

                        <VisualStateGroup x:Name="SortingStates">
                            <VisualState x:Name="Ascending">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="RenderTransform">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <ScaleTransform ScaleX="1" ScaleY="-1" />
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewHeaderCell_Selected" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="1" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Descending">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible" />
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="RenderTransform">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <ScaleTransform ScaleX="1" ScaleY="1" />
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewHeaderCell_Selected" Storyboard.TargetProperty="Opacity">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="1" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="None">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_SortIndicator" Storyboard.TargetProperty="Visibility">
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed" />
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>

                    </VisualStateManager.VisualStateGroups>

                </Grid>
            </ControlTemplate>
            <Style x:Key="headerCellWithCustomFilteringStyle" TargetType="gridView:GridViewHeaderCell">
                <Setter Property="Template" Value="{StaticResource headerCellWithCustomFilteringTemplate}" />
                <Setter Property="Background" Value="{StaticResource GridViewHeaderBackground}" />
                <Setter Property="BorderBrush" Value="{StaticResource GridViewHeaderCellInnerBorderBrush}" />
                <Setter Property="BorderThickness" Value="0,0,2,1" />
                <Setter Property="Foreground" Value="{StaticResource GridViewHeaderCellForeground}" />
                <Setter Property="FontWeight" Value="Bold" />
            </Style>






    And also, another thing that I'm not sure I have been clear enough:
    I DO NOT want to catch KeyPress in the page; I want to catch it in my custom column implementation ..

    Tnx for your effort, I really appreciate it :)



  6. Dario
    Dario  avatar
    29 posts
    Member since:
    Mar 2009

    Posted 27 Aug 2009 Link to this post

    hi Stefan, Milan,
    I feel I haven't been very good at explaining my problem, so I have created a new thread that is a little bit more to the point.
    Here it is:
Back to Top