我有一个带有 2 个模板的自定义 UserControl。我必须从第一个模板中的控件绑定到第二个模板中的控件。
当我尝试为目标控件命名时,我得到:
无法在元素“RichTextBox”上设置名称属性值“TheRichTextBox”。“RichTextBox”在元素“CustomElement”的范围内,当它在另一个范围中定义时,它已经注册了一个名称。
所以我必须使用相对绑定,但我唯一的选择是向上或向下查找可视化树。
这种情况有没有好的解决方案?
<local:CustomElement Title="CustomElementInstance" >
<local:CustomElement.SubHeaderContainer>
<StackPanel Orientation="Horizontal">
<ToggleButton
IsChecked="{Binding Path=KladblokEditingState}"
Command="{Binding Path=UpdateKladblokCommand}" CommandParameter="{Binding TheRichTextBox????, Path=Document}"/>
</StackPanel>
</local:CustomElement.SubHeaderContainer >
<RichTextBox IsReadOnly="{Binding Path=KladblokEditingNotState}"
local:RichTextBoxHelper.DocumentXaml="{Binding Path=Kladblok.KladblokDocument}" />
</local:CustomElement>