<Button x:Name="button1" >
            <Button.Template>
                <ControlTemplate>
                    <Grid>
                        <TextBox Height="57"  HorizontalAlignment="Left" Margin="46,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="190" FontSize="40" />
                    </Grid>
                </ControlTemplate>
            </Button.Template>
        </Button>        <Button Name="button2" Content="Button" Height="23" HorizontalAlignment="Left" Margin="108,176,0,0"  VerticalAlignment="Top" Width="75" Click="button1_Click" />如何将 textBox1 的Text属性绑定到button2的content属性上wpf

解决方案 »

  1.   

           <Button x:Name="button1">
                <Button.Template>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <TextBox Height="57"  Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Content}"
                                     HorizontalAlignment="Left" Margin="46,12,0,0" VerticalAlignment="Top" Width="190" FontSize="40" />
                        </Grid>
                    </ControlTemplate>
                </Button.Template>
            </Button>
            <Button Name="button2" Content="{Binding ElementName=button1,Path=Content}" Height="23" HorizontalAlignment="Left" Margin="108,176,0,0"  VerticalAlignment="Top" Width="75" />
      

  2.   

    谢谢了,还有个问题就是,改变textbox的内容的时候,button上面的内容没有立即改变,而是点击button过后button上面的内容才刷新,不知都这是什么原因
      

  3.   


    Content="{Binding ElementName=button1,Path=Content,UpdateSourceTrigger=PropertyChanged}" 
      

  4.   

    Content 肯定是依赖属性。
    还是不行
      

  5.   


    Content是依赖项属性  但是也要保证你绑定到Content的TextBox的Text是依赖项属性!  试试把TextBox的Text转换成依赖项属性在绑定   试下应该能即时刷新
      

  6.   

    Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Content}"
    这个加上UpdateSourceTrigger=PropertyChanged
      

  7.   

    参考   http://blog.csdn.net/datoumimi/article/details/2874573
    这篇文章里面有个Name属性和你这儿的Text属性类似 
      

  8.   


    基本上所有wpf提供的控件属性都是依赖属性,这个的关键问题是template中的数据绑定出来。
    我找到个解决方法就是将两个button绑定到同一个数据源上,就可以达到效果 。