开发者

Binding the button Content to the userControl Content

I have some userControl that contain simple b开发者_运维百科utton. I want to bind the button Content to the userControl Content - How to do it?


Set a name for the user control (for example x:Name="self") and in the Button

<Button Content={Binding ElementName=self}" />

Do you mean this or something else?


If the Button is inside the UserControl it is part of the UserControl's Content and can't recursively contain itself. The whole purpose of a UserControl is that you're explicitly defining a fixed set of Content. If you want variable Content then you should use a templated ContentControl something like this:

  <ContentControl Content="{Binding SomeVariableValue}">
    <ContentControl.Template>
      <ControlTemplate TargetType="{x:Type ContentControl}">
        <Border>
          <!-- Other content from your user control -->
          <Button Content="{TemplateBinding Content}"/>
        </Border>
      </ControlTemplate>
    </ContentControl.Template>
  </ContentControl>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜