控制模板

发布于 2024-09-26 09:11:31 字数 1036 浏览 0 评论 0原文

我对 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 来自一些不同的类。 *DesignerCanvas 是我自己的自定义画布,我想在运行时为其设置值。 如何从代码隐藏文件中访问 C# 代码中的 ActivityCanvasArea? 我是否需要更改 xaml 的声明方式?我需要将 DragThumbTemplate 应用到我的网格,以便我可以在主屏幕上的网格中移动。

I am quite new to WPF and have a basic question :
Assume the following is xaml declaration in my xaml file

<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.
*DesignerCanvas is my own custom canvas for which I want to set value at run time.
How can I access ActivitiesCanvasArea in my C# code from the code behind file?
Do I need to change the way xaml is declared. I need to apply DragThumbTemplate to my grid so that I can move around grid on main screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最初的梦 2024-10-03 09:11:31

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

如果您需要在 myButton1 的 ControlTemplate 中查找命名元素(例如 Grid),您可以使用 Template.FindName,如下所示:

//Finding the grid generated by the ControlTemplate of the Button
网格 gridInTemplate = (Grid)myButton1.Template.FindName("grid", myButton1);

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

// Finding the grid generated by the ControlTemplate of the Button
Grid gridInTemplate = (Grid)myButton1.Template.FindName("grid", myButton1);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文