访问控件模板中控件的名称。 [英] Accessing the Names of the controls inside the control template.

查看:125
本文介绍了访问控件模板中控件的名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在访问WPF中ControlTemplate内部分配的控件名称时遇到问题。



例如,我在控制模板中有一个堆栈面板......我需要对堆栈面板进行一些操作。但我无法访问堆栈面板的名称,因为它是在控制模板中声明的。



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.

<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>











从上面的编码,我想访问Grid控件的名称(PART_GridControl)。请尽快帮助我。






From the above coding, I would like to access the name of the Grid control (PART_GridControl). Kindly help me as soon as possible.

推荐答案

如果是你的控件,请使用 FrameworkElement.GetTemplateChild 方法之后模板已应用(即在 OnApplyTemplate 覆盖或更高版本,而不是在构造函数中)
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)


这篇关于访问控件模板中控件的名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆