Wpf 将按钮内容绑定到userControl内容

Wpf 将按钮内容绑定到userControl内容,wpf,binding,Wpf,Binding,我有一些包含简单按钮的用户控件。 我想将按钮内容绑定到用户控件内容-如何操作?为用户控件(例如x:name=“self”)和按钮中设置一个名称 <Button Content={Binding ElementName=self}" /> 为用户控件(例如x:name=“self”)和按钮设置名称 <Button Content={Binding ElementName=self}" /> 如果按钮位于UserControl内部,则它是UserControl内容的一部分

我有一些包含简单按钮的用户控件。
我想将按钮内容绑定到用户控件内容-如何操作?

为用户控件(例如
x:name=“self”
)和按钮中设置一个名称

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

为用户控件(例如
x:name=“self”
)和按钮设置名称

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

如果按钮位于UserControl内部,则它是UserControl内容的一部分,不能递归地包含自身。UserControl的全部用途是显式定义一组固定的内容。如果需要可变内容,则应使用模板化的ContentControl,如下所示:

  <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>

如果按钮位于UserControl内部,则它是UserControl内容的一部分,不能递归地包含自身。UserControl的全部用途是显式定义一组固定的内容。如果需要可变内容,则应使用模板化的ContentControl,如下所示:

  <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>


是否要将按钮的内容属性绑定到包含该按钮的userControl的内容,还是我没有正确阅读您的问题?:)另一种方式。。。。userControl的内容到按钮的内容…是否要将按钮的内容属性绑定到包含该按钮的userControl的内容,还是我没有正确阅读您的问题?:)另一种方式。。。。用户控件的内容转换为按钮的内容。。。