Silverlight:将属性绑定到 DependencyProperty

发布于 2024-12-24 22:32:40 字数 590 浏览 3 评论 0原文

XAML 代码:

<Canvas>
    <Button x:Name="btnCanvasButton" Content="Canvas Button"
            Canvas.Left="50" />
    <Button x:Name="btnCanvasButton2" Content="Canvas Button 2"
            Canvas.Top="25"
            Width="{Binding Path=Canvas.Left, ElementName=btnCanvasButton}" />
</Canvas>

我想将 btnCanvasButton2.Width 绑定到 btnCanvasButton.Canvas.Left,但它不起作用。

我还尝试了 Path=Canvas.LeftPropertyPath=LeftPath=LeftProperty,但也没有运气。

请指教。谢谢。

彼得

The XAML code:

<Canvas>
    <Button x:Name="btnCanvasButton" Content="Canvas Button"
            Canvas.Left="50" />
    <Button x:Name="btnCanvasButton2" Content="Canvas Button 2"
            Canvas.Top="25"
            Width="{Binding Path=Canvas.Left, ElementName=btnCanvasButton}" />
</Canvas>

I want to bind btnCanvasButton2.Width to btnCanvasButton.Canvas.Left, but it's not working.

I also tried Path=Canvas.LeftProperty, Path=Left, Path=LeftProperty, but no luck either.

Please advise. Thx.

Peter

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

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

发布评论

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

评论(1

浮生面具三千个 2024-12-31 22:32:40

您需要使用括号来绑定到附加属性。

你可以尝试:

<Button x:Name="btnCanvasButton2" Content="Canvas Button 2"
        Canvas.Top="25"
        Width="{Binding Path=(Canvas.Left), ElementName=btnCanvasButton}" />

You need to use parentheses to bind to an attached property.

You could try:

<Button x:Name="btnCanvasButton2" Content="Canvas Button 2"
        Canvas.Top="25"
        Width="{Binding Path=(Canvas.Left), ElementName=btnCanvasButton}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文