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

how to listen to click event of a button which is in the style

1 Answer 37 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 27 Dec 2012, 08:36 AM
Hi There,
i have placed a button control in the "GridViewScrollViewerTemplate", my question is  how can i listen to click event of that button is there any way that i can do it ?
I have pasted me xaml here please check once.

<ControlTemplate x:Key="GridViewScrollViewerTemplate" TargetType="{x:Type grid:GridViewScrollViewer}">
        <Grid x:Name="PART_RootPanel" Background="{TemplateBinding Background}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Grid.Row="2" CanContentScroll="{TemplateBinding CanContentScroll}"/>
            <ScrollBar x:Name="PART_VerticalScrollBar" Width="18" BorderThickness="1,0,0,0" IsTabStop="False" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Grid.Column="1" Grid.Row="2" Grid.RowSpan="1" Orientation="Vertical" ViewportSize="{TemplateBinding ViewportHeight}" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0.0" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="0,4,0,0"/>
            <ScrollBar x:Name="PART_HorizontalScrollBar" Height="18" BorderThickness="0,1,0,0" IsTabStop="False" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Grid.Column="0" Grid.Row="4" Orientation="Horizontal" ViewportSize="{TemplateBinding ViewportWidth}" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0.0" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>
            <Rectangle Grid.Column="1" Grid.Row="4" Fill="{StaticResource GridView_ScrollViewerIntersectionRectangleBackground}"/>
            <Button HorizontalAlignment="Center" Width="16" Grid.Column="1" Style="{DynamicResource ActionButtonSmallStyle}" Height="16" VerticalAlignment="Center">
                 <Viewbox>
            <Canvas Height="16" Width="16">
                <Path Data="M0,15.16L14.908,15.16L14.908,-0.00100000000000122L0,-0.00100000000000122z" Height="15.161" Canvas.Left="0.25" Stretch="Fill" Canvas.Top="0.249" Width="14.908">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="1.004,0.996" StartPoint="-0.004,0.004">
                            <GradientStop Color="#FF4578AB" Offset="0"/>
                            <GradientStop Color="#FF4578AB" Offset="0.45454400777816772"/>
                            <GradientStop Color="#FF305870" Offset="0.56362897157669067"/>
                            <GradientStop Color="#FF305870" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="M13.853,14.216L1.018,14.216L1.018,1.162L13.853,1.162z" Height="13.054" Canvas.Left="1.268" Stretch="Fill" Canvas.Top="1.412" Width="12.835">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                            <GradientStop Color="#FFD2DCEE" Offset="0"/>
                            <GradientStop Color="#FFF6FBF9" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="M5.74,5.353L2.979,5.353L2.979,2.592L5.74,2.592z" Height="2.761" Canvas.Left="3.229" Stretch="Fill" Canvas.Top="2.842" Width="2.761">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
                            <GradientStop Color="#FF708CBC" Offset="0"/>
                            <GradientStop Color="#FF708CBC" Offset="0.45454400777816772"/>
                            <GradientStop Color="#FF4578AB" Offset="0.56362897157669067"/>
                            <GradientStop Color="#FF4578AB" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="M5.11,4.723L3.608,4.723L3.608,3.221L5.11,3.221z" Height="1.502" Canvas.Left="3.858" Stretch="Fill" Canvas.Top="3.471" Width="1.502">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,-0.001">
                            <GradientStop Color="#FFF6FBF9" Offset="0"/>
                            <GradientStop Color="#FFD2DCEE" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="F1M3.4604,3.3555L2.9014,3.9155L4.0584,5.3705L4.6544,5.3705L6.1474,2.0865L5.5124,1.4535L4.3554,4.3995z" Fill="#FFAA1E2D" Height="3.917" Canvas.Left="3.151" Stretch="Fill" Canvas.Top="1.704" Width="3.246"/>
                <Path Data="M5.74,9.323L2.979,9.323L2.979,6.563L5.74,6.563z" Height="2.76" Canvas.Left="3.229" Stretch="Fill" Canvas.Top="6.813" Width="2.761">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
                            <GradientStop Color="#FF708CBC" Offset="0"/>
                            <GradientStop Color="#FF708CBC" Offset="0.45454400777816772"/>
                            <GradientStop Color="#FF4578AB" Offset="0.56362897157669067"/>
                            <GradientStop Color="#FF4578AB" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="M5.11,8.694L3.608,8.694L3.608,7.193L5.11,7.193z" Height="1.501" Canvas.Left="3.858" Stretch="Fill" Canvas.Top="7.443" Width="1.502">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFF6FBF9" Offset="0"/>
                            <GradientStop Color="#FFD2DCEE" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="M5.74,13.319L2.979,13.319L2.979,10.559L5.74,10.559z" Height="2.76" Canvas.Left="3.229" Stretch="Fill" Canvas.Top="10.809" Width="2.761">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
                            <GradientStop Color="#FF708CBC" Offset="0"/>
                            <GradientStop Color="#FF708CBC" Offset="0.45454400777816772"/>
                            <GradientStop Color="#FF4578AB" Offset="0.56362897157669067"/>
                            <GradientStop Color="#FF4578AB" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="M5.11,12.69L3.608,12.69L3.608,11.188L5.11,11.188z" Height="1.502" Canvas.Left="3.858" Stretch="Fill" Canvas.Top="11.438" Width="1.502">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FFF6FBF9" Offset="0"/>
                            <GradientStop Color="#FFD2DCEE" Offset="1"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
                <Path Data="F1M11.697,4.989L7.313,4.989L7.313,3.851L11.697,3.851z" Fill="#FFA6A8AB" Height="1.138" Canvas.Left="7.563" Stretch="Fill" Canvas.Top="4.101" Width="4.384"/>
                <Path Data="F1M11.697,8.573L7.313,8.573L7.313,7.435L11.697,7.435z" Fill="#FFA6A8AB" Height="1.138" Canvas.Left="7.563" Stretch="Fill" Canvas.Top="7.685" Width="4.384"/>
                <Path Data="F1M11.697,12.375L7.313,12.375L7.313,11.236L11.697,11.236z" Fill="#FFA6A8AB" Height="1.139" Canvas.Left="7.563" Stretch="Fill" Canvas.Top="11.486" Width="4.384"/>
            </Canvas>
        </Viewbox>
            </Button>
        </Grid>
    </ControlTemplate>

Thanks in Advance,
Srinivas.

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 27 Dec 2012, 08:44 AM
Hi,

You should not listen to events but use MVVM and bind the button Command to your view-model. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Ravi
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or