我有两个文本框在wpf mvvm中独立工作。但是现在我想在一个复选框的基础上将一个文本框的输入绑定到其他文本框。WPF - 绑定文本框的内容其他文本框
<Label Grid.Row="4" Grid.Column="0" Style="{StaticResource StlLblForm}" Margin="0,5">First Name:</Label>
<TextBox Grid.Row="4" MaxLength="10" Grid.Column="1" Style="{StaticResource StlTxtForm}" Text="{Binding FirstName}" Grid.ColumnSpan="2" Margin="0,1,0,11" />
<Label Grid.Row="5" Grid.Column="0" Style="{StaticResource StlLblForm}" Margin="0,5">Last Name:</Label>
<TextBox Grid.Row="5" Grid.Column="1" Style="{StaticResource StlTxtForm}" Text="{Binding LastName}" AcceptsReturn="True" Grid.ColumnSpan="2" Margin="0,1,0,11" />
<CheckBox Content="CopyFirstNameToLast" />
因此,当我选中复选框时,它将名字复制到姓氏。我可以做到这一点,没有代码背后。如果是,那么如何?
你不必onproperty改变notificatio n – ntohl
将名字绑定到XAML中的名字很简单,请参阅http://stackoverflow.com/questions/9586956/how-to-bind-a-controls-property-to-another-controls-property获取更多信息。但是,复选框使其更加复杂,您可能必须编写一个值转换器才能完成此项工作。 –
也许这样? HTTP://计算器。com/questions/23225751/wpf-binding-to-two-properties –