在代码隐藏中使用附加属性进行控制 (WPF)

发布于 2024-09-08 11:11:59 字数 415 浏览 1 评论 0原文

我有 UserControl1,我想创建它的实例并在另一个 UserControl2 后面的代码中为其设置附加属性。 换句话说,我在 UserControl2 中有:

<UserControl2>
  <Canvas>
  </Canvas>
</UserControl2>

我想做:

<UserControl2>
  <Canvas>
     <UserControl1 Canvas.Left="100" ... />
  </Canvas>
</UserControl2>

如何在 UserControl2 的代码后面创建带有附加属性的 UserControl1?

I have UserControl1 and I want to create it's instance and set attached property for it in the code behind of the other UserControl2.
The other words, I have in the UserControl2:

<UserControl2>
  <Canvas>
  </Canvas>
</UserControl2>

And I want to do:

<UserControl2>
  <Canvas>
     <UserControl1 Canvas.Left="100" ... />
  </Canvas>
</UserControl2>

How can I create UserControl1 with attached property in code behind of the UserControl2?

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

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

发布评论

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

评论(1

月隐月明月朦胧 2024-09-15 11:11:59
UserControl1 ctrl = new UserControl1();
Canvas.SetLeft(ctrl, 100);
UserControl1 ctrl = new UserControl1();
Canvas.SetLeft(ctrl, 100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文