110,536
社区成员
发帖
与我相关
我的任务
分享
<Window x:Class="WPF2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF2"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="136,83,0,0" TextWrapping="Wrap"
Text="{Binding ElementName=button, Path=Content, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Top" Width="120"/>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="155,159,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</Window>
private void button_Click(object sender, RoutedEventArgs e)
{
textBox.Text = "300";
}
如果为先前已具有 Binding 表达式的属性设置了本地值,则会完全移除 Binding。
原文是local value,不是指你这里的Text属性,是DependencyProperty所保存的一个值,可以通过DependencyObject.ClearValue清除 http://www.wpftutorial.net/DependencyProperties.html