Click here to Skip to main content
16,018,057 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am facing problem in Accessing the names of the controls assigned inside the ControlTemplate in WPF.

For Example, I have a stack panel inside the Control Template... I need to do some operations with the stack panel. But I could not able to access the name of the stack panel since it is declared inside the Control Template.

XML
<ControlTemplate x:Key="gridTemplate">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="25"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <dxb:BarManager Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Name="barmanager1" VerticalAlignment="Stretch" >

                            <dxb:BarManager.Items>
                                <dxb:BarButtonItem Name="Add1" Content="Add" CommandParameter="Add" Command="{Binding ParamGroupGeneralCommand}" />
                                <!--<dxb:BarButtonItem Name="Delete1" Content="Delete" Command="{Binding ParamGroupGeneralCommand}" CommandParameter ="Delete" />-->
                                <dxb:BarButtonItem Name="Delete1" Content="Delete" Command="{Binding ParamGroupDelGeneralCommand}" CommandParameter ="{Binding Path=View.FocusedRow, ElementName=PART_GridControl}" />

                            </dxb:BarManager.Items>
                            <dxg:GridControl Name="PART_GridControl" ItemsSource="{Binding ParameterInfo}" AutoPopulateColumns="False" Height="250" >

                                <dxg:GridControl.Columns>
                                    <dxg:GridColumn FieldName="Id" Header="Id" Visible="True"/>
                                    <dxg:GridColumn FieldName="GroupName" Header="Group Name"/>
                                    <dxg:GridColumn FieldName="GroupDescription" Header="Description"/>
                                </dxg:GridControl.Columns>
                                <dxg:GridControl.View>
                                    <dxg:TableView Name="view" AutoWidth="True" ShowGroupPanel="False" VerticalScrollbarVisibility="Visible"  >
                                        <dxg:TableView.RowCellMenuCustomizations>
                                            <dxb:BarButtonItemLink BarItemName="Add1"/>
                                            <dxb:BarButtonItemLink BarItemName="Delete1"/>
                                        </dxg:TableView.RowCellMenuCustomizations>
                                    </dxg:TableView>
                                </dxg:GridControl.View>
                            </dxg:GridControl>
                        </dxb:BarManager>
                        <Button Grid.Row="1" Grid.Column="0" Content="Save" Height="25" Width="50" HorizontalAlignment="Right" CommandParameter="SaveParamGroup" Command="{Binding ParamGroupGeneralCommand}" Name="SaveButton" ></Button>
                        <Button Grid.Row="1" Grid.Column="1" Content="Close" Height="25" Width="50" HorizontalAlignment="Left" Command="{Binding ParamGroupCloseGeneralCommand}" CommandParameter ="{Binding Path=View.FocusedRow, ElementName=PART_GridControl}"></Button>
                    </Grid>
            </ControlTemplate>





From the above coding, I would like to access the name of the Grid control (PART_GridControl). Kindly help me as soon as possible.
Posted
Updated 2-Apr-13 21:39pm
v2

1 solution

if it is your control, use FrameworkElement.GetTemplateChild method after template has been applied (i.e. in the OnApplyTemplate override or later, not in the constructor)
 
Share this answer
 
v2

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