WPF - 当依赖属性是 XAML 中的另一个控件时该怎么办

发布于 2024-09-07 21:02:36 字数 849 浏览 4 评论 0原文

我希望这是我今天的最后一个问题。我很着急,谷歌并没有多大帮助(或者我正在搜索错误的地方)。

我创建了一些自定义属性和行为,以便我的单选按钮可以更改我的标签内容和文本框的掩码。

我可以将字符串作为属性传递,但是如何将另一个控件作为属性传递? (AdjustedLabel 是 Label 类型)

    <RadioButton i:CPF_CNPJAdjustBehavior.LabelContent="Apple" i:CPF_CNPJAdjustBehavior.AdjustedLabel="??????????" Content="CPF" Height="16" HorizontalAlignment="Left" Margin="30,216,0,0" Name="radioButton1" VerticalAlignment="Top" GroupName="a" IsChecked="True">         
        <int:Interaction.Behaviors>
            <i:CPF_CNPJAdjustBehavior/>
        </int:Interaction.Behaviors>
    </RadioButton>
    <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="20,81,0,0" Name="MyLabel" VerticalAlignment="Top" />

我要在“?????????”中写什么?将AdjustedLabel 设置为名为“MyLabel”的标签?

预先感谢

克拉克

I'm hoping this will be my last question today. I'm in a hurry and google is not helping much (that or I'm searching the wrong places).

I created some custom properties and behaviors so my RadioButtons can alter my labels Content and the mask of my TextBoxes.

I could pass a String as a property, but how do I pass another control as a property? (AdjustedLabel is of type Label)

    <RadioButton i:CPF_CNPJAdjustBehavior.LabelContent="Apple" i:CPF_CNPJAdjustBehavior.AdjustedLabel="??????????" Content="CPF" Height="16" HorizontalAlignment="Left" Margin="30,216,0,0" Name="radioButton1" VerticalAlignment="Top" GroupName="a" IsChecked="True">         
        <int:Interaction.Behaviors>
            <i:CPF_CNPJAdjustBehavior/>
        </int:Interaction.Behaviors>
    </RadioButton>
    <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="20,81,0,0" Name="MyLabel" VerticalAlignment="Top" />

What do I have do write in "?????????" to set AdjustedLabel to the label named "MyLabel" ?

Thanks in Advance

Clark

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

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

发布评论

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

评论(1

为你拒绝所有暧昧 2024-09-14 21:02:36

AdjustedLabel="{Binding ElementName=MyLabel}" 将执行您正在搜索的操作。

考虑阅读一些文档以开始使用 WPF、绑定、依赖属性和 XAML 语法。您可以从 XAML 语法详细信息开始,依赖属性概述数据绑定概述

AdjustedLabel="{Binding ElementName=MyLabel}" will do what you're searching for.

Consider reading some documentation for getting started with WPF, Bindings, Dependency Properties and XAML syntax. You could start with XAML Syntax In Detail, Dependency Properties Overview and Data Binding Overview.

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