WPF 共享依赖属性?
我有以下情况:
FooControl:
我需要这个控件能够将内容放置在特定区域,所以我使用了 Canvas 控件。
<Canvas>
<local:FooPanel x:Name="FooItemsPanel" Canvas.Top="0" Canvas.Left="0" Panel.ZIndex="0" IsItemsHost="True" />
<ContentPresenter x:Name="PART_FooContentHost" Canvas.Top="?" Canvas.Left="?" Panel.ZIndex="1" ContentSource="FooContent" />
</Canvas>
FooPanel:
按特定顺序排列所有子项,并指定内容所在的区域 (Rect
)。
But, here's the problem. FooPanel isn't really referenced from FooControl. How can I get the coordinates from the FooPanel into the FooControl? I figure it's some DependencyProperty trick, but I'm not sure how.
我将 Rect 转换为 DependencyProperty,但我不太确定如何从 FooControl.cs 中获取它(我宁愿避免在 XAML 中进行绑定,因为如果控件样式被重写,它就会消失。 ..
I have the following situation:
FooControl:
I need for this control to be able to place content in a specific area, so I used a Canvas control for it.
<Canvas>
<local:FooPanel x:Name="FooItemsPanel" Canvas.Top="0" Canvas.Left="0" Panel.ZIndex="0" IsItemsHost="True" />
<ContentPresenter x:Name="PART_FooContentHost" Canvas.Top="?" Canvas.Left="?" Panel.ZIndex="1" ContentSource="FooContent" />
</Canvas>
FooPanel:
Arranges all the children item in a specific order and designates an area (Rect
) for where the content should go.
But, here's the problem. FooPanel isn't really referenced from FooControl. How can I get the coordinates from the FooPanel into the FooControl? I figure it's some DependencyProperty trick, but I'm not sure how.
I turned the Rect into a DependencyProperty but I'm not really sure how I can get it from within my FooControl.cs (I'd rather avoid doing binding in the XAML because well, if the control style is overridden it would go away...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白你的问题。它可能会寻找一些实际上与 WPF 布局和管理其控件和属性的方式不合逻辑的东西。
使用附加属性和一些数据绑定可能是可能的。
您还可以查看如何测量和安排(另一个)布局在WPF中工作,因为这就是父级的方式定位它的孩子。
I don't really understand your question. It might look for something, that is actualy not logical in the way how WPF layouts and manages its controls and properties.
It might be possible with Attached Property and some databinding.
You might also look how Measure and Arrange(another) layout works in WPF, beccause thats how parent positions its children.