WPF 数据绑定
<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
[解决办法]
<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" />
[解决办法]
Content="{Binding ElementName=button1,Path=Content,UpdateSourceTrigger=PropertyChanged}"
------解决方案--------------------
不是依赖项属性 不能即时刷新
[解决办法]
Content是依赖项属性 但是也要保证你绑定到Content的TextBox的Text是依赖项属性! 试试把TextBox的Text转换成依赖项属性在绑定 试下应该能即时刷新
[解决办法]
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Content}"
这个加上UpdateSourceTrigger=PropertyChanged
[解决办法]
参考 http://blog.csdn.net/datoumimi/article/details/2874573
这篇文章里面有个Name属性和你这儿的Text属性类似