元素绑定——WPF从源对象提取一些信息,并用这些对象设置目标对象的属性。
OneWay |
当源属性变化时更新目标属性 |
TwoWay | 当源属性变化时更新目标属性,并且当目标属性变化时同时更新源属性 |
OneTime | 最初根据源属性的值设置目标属性 |
OneWayToSource | 与OneWay类型相似,但方向相反 |
Default | 依赖于目标属性 |
<StackPanel>
<Slider Name="slider1" Minimum="0" Maximum="40" TickFrequency="1" Value="20" TickPlacement="TopLeft"></Slider>
<TextBlock Name="textBlock" Text="Lynn Test"
FontSize="{Binding Source=slider1,Path=Value,Mode=TwoWay}"
/>
<Button Name="button1" Content="Change TextBlock FontSize" Click="button1_Click" Height="50"/>
<Button Name="button2" Content="" Height="45"/>
</StackPanel>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Binding bing = new Binding();
bing.Source = this.slider1;
bing.Path = new PropertyPath("Value");
bing.Mode = BindingMode.TwoWay;
this.textBlock.SetBinding(TextBlock.FontSizeProperty, bing);
}
原文:https://www.cnblogs.com/LynnXue/p/12637373.html