Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF How to set checkbox in Gridview binding in code behind

Tags:

c#

wpf

style that I have to create in code-behind. It has a checkbox that looks like this..

     <GridView>


  <GridViewColumn Width="30">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel>
                                            <CheckBox/>
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>-->
                            <GridViewColumn  Header="Groups"  DisplayMemberBinding="{Binding Groups}"/>
                           <GridViewColumn Header="SiteTitle" DisplayMemberBinding="{Binding SiteTitle}"/>
                            <GridViewColumn  Header="SiteUrl" DisplayMemberBinding="{Binding SiteUrl}"/>
                        </GridView>

How I do in code-behind?

like image 944
Sanjay Ranavaya Avatar asked Apr 04 '18 05:04

Sanjay Ranavaya


1 Answers

Just add this style in Resources and give it a x:Name.Let's assume the given name is CustomCheckboxTemplate , then a sample code will look like :

 DynamicallyCreatedCheckbox.Style = (Style)FindResource("CustomCheckboxTemplate");

Hope this helps :)

like image 122
Christopher H. Avatar answered Nov 09 '22 20:11

Christopher H.