<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
解决方案 »
- 存储过程对象名为空,急等!!顶贴就送分
- 用过FCKeditor控件的进
- 定义一个DataSet的对象,如何在2个按钮下起作用?
- c#.net里面如何调用c++.net编译的dll里的静态方法?
- Serv-U的ftp服务器用户不能登陆的问题
- 在winform中,我要从数据库中查询大量的数据,并用DATAgrid显示,但是在处理数据,还未在datagrid显示前,窗口老是像死掉状,我想用线程
- c# 关于office word求助
- 自动登录csdn的代码谁有啊,记得原来csdn有这段代吗,有没有人知道
- 关于把一个字符串作为组件名称转换为相应组件类型的问题(在线)
- c#和数据库
- 1.# define SPP 是什么意思 2.main函数是如何开始运行的
- 求教 c++部分代码相对应的c#里的代码怎么写~
<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转换成依赖项属性在绑定 试下应该能即时刷新
这个加上UpdateSourceTrigger=PropertyChanged
这篇文章里面有个Name属性和你这儿的Text属性类似
基本上所有wpf提供的控件属性都是依赖属性,这个的关键问题是template中的数据绑定出来。
我找到个解决方法就是将两个button绑定到同一个数据源上,就可以达到效果 。