简体   繁体   English

ControlTemplate

[英]ControlTemplate

I am quite new to WPF and have a basic question : Assume the following is xaml declaration in my xaml file 我是WPF的新手,有一个基本问题:假设以下是我的xaml文件中的xaml声明

<ContentControl x:Name="interactionActivityContent" Loaded="interactionActivityContent_Loaded">
<shapes:BaseShape.DragThumbTemplate >
    <ControlTemplate x:Name="interactionActivityTemplate">
        <Grid AllowDrop="True" x:Name="GridTest" >
            <Rectangle Name="Interaction" Fill="Yellow" Stroke="Green" StrokeThickness="2" IsHitTestVisible="True" AllowDrop="True"></Rectangle>
            <local:DesignerCanvas x:Name="ActivitiesCanvasArea" Margin="1,1,1,1" IsHitTestVisible="True" AllowDrop="True" Background="Blue"></local:DesignerCanvas>
        </Grid>
    </ControlTemplate>
</shapes:BaseShape.DragThumbTemplate>


*shapes:BaseShape.DragThumbTemplate is coming from some different class. * shapes:BaseShape.DragThumbTemplate来自不同的类。 *DesignerCanvas is my own custom canvas for which I want to set value at run time. * DesignerCanvas是我自己的自定义画布,我想在运行时为其设置值。 How can I access ActivitiesCanvasArea in my C# code from the code behind file? 如何从文件背后的代码以C#代码访问ActivitiesCanvasArea? Do I need to change the way xaml is declared. 我是否需要更改xaml的声明方式。 I need to apply DragThumbTemplate to my grid so that I can move around grid on main screen. 我需要将DragThumbTemplate应用于我的网格,以便可以在主屏幕上的网格周围移动。

From http://blogs.msdn.com/b/wpfsdk/archive/2007/03/16/how-do-i-programmatically-interact-with-template-generated-elements-part-i.aspx 来自http://blogs.msdn.com/b/wpfsdk/archive/2007/03/16/how-do-i-programmatically-interact-with-template-generated-elements-part-i.aspx

If you need to find a named element in the ControlTemplate of myButton1, like the Grid, you can use Template.FindName like so: 如果需要在myButton1的ControlTemplate中找到一个命名元素,例如Grid,则可以使用Template.FindName,如下所示:

// Finding the grid generated by the ControlTemplate of the Button Grid gridInTemplate = (Grid)myButton1.Template.FindName("grid", myButton1); //查找由Button的ControlTemplate生成的网格gridInTemplate =(Grid)myButton1.Template.FindName(“ grid”,myButton1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM