Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF DataGrid control, i also have a DataTemplate (CheckBox) control in it, which is shown below

What i want a achieve now, is to access the variable name of the check-box control in the DataTemplate, from my C# Code. Thanks in advance.


XML
<datagridtemplatecolumn width="50" minwidth="20">
                                                <datagridtemplatecolumn.headertemplate>
                                                    <datatemplate>
                                                        &lt;!--<textblock text="Manage" fontsize="18" foreground="#FF666666" horizontalalignment="Center" margin="50,0" />--&gt;
                                                        <stackpanel horizontalalignment="Center" verticalalignment="Center" margin="10,0,0,0">
                                                            <checkbox x:name="chkBox_CheckAllStuRow" width="20" height="auto" checked="chkBox_CheckAllStuRow_Checked" xmlns:x="#unknown" />
                                                        </stackpanel>
                                                    </datatemplate>
                                                </datagridtemplatecolumn.headertemplate>
                                                <datagridtemplatecolumn.celltemplate>
                                                    <datatemplate>
                                                        <stackpanel horizontalalignment="Center" verticalalignment="Center">
                                                            <checkbox x:name="chkBox_CheckStuRow" width="20" height="20" xmlns:x="#unknown" />
                                                        </stackpanel>
                                                    </datatemplate>
                                                </datagridtemplatecolumn.celltemplate>
                                            </datagridtemplatecolumn>


                                            <datagridtextcolumn header="First Name" width="*" minwidth="100" binding="{Binding f_name}" />
                                            <datagridtextcolumn header="Last Name" width="*" minwidth="100" binding="{Binding l_name}" />
                                            <datagridtextcolumn header="Phone No" width="*" minwidth="100" binding="{Binding phone}" />

                                            <datagridtemplatecolumn width="auto" minwidth="250">
                                                <datagridtemplatecolumn.headertemplate>
                                                    <datatemplate>
                                                        <textblock text="Manage" fontsize="18" foreground="#FF666666" horizontalalignment="Center" margin="50,0" />
                                                    </datatemplate>
                                                </datagridtemplatecolumn.headertemplate>
                                                <datagridtemplatecolumn.celltemplate>
                                                    <datatemplate>
                                                        <stackpanel orientation="Horizontal" horizontalalignment="Center">
                                                            &lt;Button x:Name="btn_ViewStu"  Content="View" FontSize="14" HorizontalAlignment="Center" Height="27" Margin="3" Style="{DynamicResource ActiveButtonStyle}" Width="65" Click="btn_ViewStu_Click"  /&gt;
                                                            &lt;Button x:Name="btn_DeleteStu" Content="Delete" FontSize="14" HorizontalAlignment="Center" Height="27" Margin="3" Style="{DynamicResource DangerButtonStyle}" Width="65" Click="btn_DeleteStu_Click"  /&gt;
                                                            &lt;Button x:Name="btn_withDrwStu" Content="Withdraw" FontSize="14" HorizontalAlignment="Center" Height="27" Margin="3" Style="{DynamicResource DangerButtonStyle}" Width="70" /&gt;
                                                        </stackpanel>
                                                    </datatemplate>
                                                </datagridtemplatecolumn.celltemplate>
                                            </datagridtemplatecolumn>
Posted
Updated 21-Mar-16 19:45pm
v3

1 solution

Hi, use the following link, I hope this is what exactly you want.
c# - how to access a control within Data Template from code behind? - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900