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

How to align checkbox to center in GridViewDataColumn

2 Answers 607 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marthayaputra
Top achievements
Rank 1
Marthayaputra asked on 02 Oct 2013, 05:57 AM
Hello Experts,

I have tried several ways to make the checkbox centered in GridViewDataColumn with no luck. Could anyone help me please? Below is my XAML code
Check box section
<telerik:GridViewDataColumn CellStyle="{StaticResource MyCheckBoxStyle}">
                       <telerik:GridViewDataColumn.CellTemplate>
                           <DataTemplate>
                               <!--<CheckBox x:Name="chk"  Content="" Click="Chk_OnClick" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="65,0,0,0"  IsChecked="{Binding IsSelected, Mode=TwoWay}">-->
                               <CheckBox x:Name="chk" Content="" Click="Chk_OnClick" IsChecked="{Binding IsSelected, Mode=TwoWay}">
                               </CheckBox>
                           </DataTemplate>
                       </telerik:GridViewDataColumn.CellTemplate>
                       <telerik:GridViewDataColumn.Header>
                           <CheckBox x:Name="chkAll" IsChecked="{Binding HasAllShopsMarked, Mode=TwoWay}" Loaded="ChkAll_Shop" Checked="ChkAll_Shop" Unchecked="ChkAll_Shop"
                                                             Content="{Binding ResourceSet[MODULE_SETTINGS_SHOP_AUD_BATCH_UPDATE_ASSIGN_LBL], Source={StaticResource localSvc}, FallbackValue=Assign}" 
                                                             Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="10,0,0,0" />
                       </telerik:GridViewDataColumn.Header>
                   </telerik:GridViewDataColumn>

MyCheckBoxStyle Section :
<Style x:Key="MyCheckBoxStyle" TargetType="telerik:GridViewCell">
           <Setter Property="HorizontalContentAlignment" Value="Center"/>
       </Style>

Thanks in advance.

Regards,
Putra

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 02 Oct 2013, 06:53 AM
Hi,

In case you redefine the CellTemplate, then you should take care of centering the element you have placed for it.
For example you can center the CheckBox similar to:
<telerik:GridViewDataColumn.CellTemplate>
  <DataTemplate>
    <CheckBox IsChecked="{Binding IsSelected}" HorizontalAlignment="Center" />
  </DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>


Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Marthayaputra
Top achievements
Rank 1
answered on 02 Oct 2013, 07:11 AM
Hi Didie,
Thanks for your reply. I tried your suggestion but the result was still the same.
It's still align on the left.

Regards
Tags
GridView
Asked by
Marthayaputra
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Marthayaputra
Top achievements
Rank 1
Share this question
or