0

I have a custom UserControl with 2 templates. I have to bind from a control in the first template to a control in the second template.

When I try to give the target control a name, then I get:

Cannot set Name attribute value 'TheRichTextBox' on element 'RichTextBox'. 'RichTextBox' is under the scope of element 'CustomElement', which already had a name registered when it was defined in another scope.

So I have to work with relative binding, but my only options are to look up or down the visual tree.
Is there a good solution for this scenario?

    <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>
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Peter
  • 489
  • 3
  • 16
  • Possible duplicate of [How to create a WPF UserControl with NAMED content](http://stackoverflow.com/questions/751325/how-to-create-a-wpf-usercontrol-with-named-content) – Adi Lester Aug 02 '12 at 08:01
  • If the only solution here would be to create a WPF UcerControl With NAMED content, wich doesn't look very straightforward, you're maybe right. But I hope there is a better solution. So my question is wider then the one you reference – Peter Aug 02 '12 at 08:36

0 Answers0