1

次の xaml コードがあります。

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>

RichTextBox の可視性を CheckBox のチェック状態にバインドしたいと考えています。

<RichTextBox Visibility="{Binding IsChecked,ElementName=chk,Converter={StaticResource b2v}}" />

今のところ問題ありません。しかし、問題は、CheckBox に Name プロパティがないことです (時間をかけてコピーされるため、名前を付けることができません)。

そのため、CheckBox の添付プロパティがあります。

<CheckBox local:MyUIElementAttributes.AttachedElementType="TitleCheckbox"/>

ここで、この添付プロパティを使用して、RichTextBox の可視性がバインドされる CheckBox を識別したいと考えています。

どうやってやるの?添付プロパティにバインドし、その値を確認して可視性を設定する必要があります。

ありがとうございました!

4

1 に答える 1

0

If I understand you correctly, you want to use the value of your Attached Property as the value of the Binding.ElementName property. From the Binding.ElementName Property page at MSDN:

Property Value

The value of the Name property or x:Name Directive of the element of interest. You can refer to elements in code only if they are registered to the appropriate NameScope through RegisterName. For more information, see WPF XAML Namescopes.

Having read this and the linked page, it seems as though you can use the NameScope.RegisterName method instead of setting the Name property. You should then be able to refer to the name set with this method in the Binding.ElementName property without issue.

Disclaimer: I have not tried this before and could be mistaken.

于 2013-09-13T13:39:57.730 に答える