WPF绑定模式
来源:互联网 发布:我的世界局域网java 编辑:程序博客网 时间:2024/06/13 10:37
WPF支持OneWay,TwoWay,OneTime,Default和OneWayToSource等多种绑定模式
无论是目标属性还是源属性,只要发生了更改,TwoWay 就会更新目标属性或源属性。
OneWay 仅当源属性发生更改时更新目标属性。
OneTime 仅当应用程序启动时或 DataContext 进行更改时更新目标属性。
OneWayToSource 在目标属性更改时更新源属性。
Default:使用目标属性的默认 Mode 值。
下面的例子,展示了这几种绑定模式的区别:
代码<Window x:Class="WPF_Started.Controls.DataBinding.BindingMode"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="BindingMode" Height="400" Width="300">
<StackPanel>
<ScrollBar Name="scroll" Orientation="Horizontal" Margin="20" Maximum="100" LargeChange="10" SmallChange="1" />
<Label Content="OneWay:" Height="30" />
<TextBox Name="scrollValue" Height="20" Width="200" HorizontalAlignment="Center"
Text="{Binding ElementName=scroll, Path=Value, Mode=OneWay}" />
<Label Content="TwoWay:" Height="30" />
<TextBox Name="scrollValueTwoWay" Height="20" Width="200" HorizontalAlignment="Center"
Text="{Binding ElementName=scroll, Path=Value, Mode=TwoWay}" />
<Label Content="OneTime:" Height="30" />
<TextBox Name="scrollValueOneTime" Height="20" Width="200" HorizontalAlignment="Center"
Text="{Binding ElementName=scroll, Path=Value, Mode=OneTime}" />
<Label Content="OneWayToSource:" Height="30" />
<TextBox Name="scrollValueOneWayToSource" Height="20" Width="200" HorizontalAlignment="Center"
Text="{Binding ElementName=scroll, Path=Value, Mode=OneWayToSource}" />
<Label Content="Default:" Height="30" />
<TextBox Name="scrollValueDefault" Height="20" Width="200" HorizontalAlignment="Center"
Text="{Binding ElementName=scroll, Path=Value, Mode=Default}" />
</StackPanel>
</Window>运行结果显示,OneWay,TwoWay,Default模式下TextBox中的值随着滑块的位置而变化。OneTime模式下总是滑块的初始值0,这种模式下TextBox的值取决于ScrollBar的初始值。
OneWayToSource模式下,在TextBox中输入20,滑动条滑块会自动滑倒20的位置,但当滑动条继续滑动时候,该模式下TextBox的值并不随着滑动条的滑动而改变。
0 0
- WPF绑定模式
- WPF绑定模式
- WPF绑定Binding及模式
- 跟我一起玩WPF-绑定模式
- WPF数据绑定之4种绑定模式
- WPF-绑定
- WPF绑定
- wpf数据绑定的三种模式:oneTime、OneWay、.TwoWay
- WPF的5种绑定模式(mode)
- MVVM设计模式和WPF中的实现 (事件绑定)
- WPF之数据绑定
- WPF之数据绑定
- WPF之绑定数据
- wpf数据绑定常见问题
- WPF数据绑定
- WPF 数据绑定[1]
- WPF 数据绑定[2]
- WPF 数据绑定[3]
- linux顶半部和底半部中断机制
- 《c++ primer》5——c风格字符串
- SOCK/HTTP代理协议解析
- C++对象模型详解
- Android Paint属性
- WPF绑定模式
- MyEclipse10下开发第一个Hibernate小程序
- 【坑坑坑坑坑】dlsym----undefined symbol: hello
- Json 遍历和后台json格式的传递
- android(7) 360界面的实现
- WPF数据绑定
- 第四章笔记
- 用Geogebra绘制一种五角星形曲线
- cocos2dx3.3 打包官方cpp-tests例子Apk