WPF的绑定模式(mode)是枚举的 枚举值共有5个
1:OneWay(源变就更新目标属性)
2:TwoWay(源变就更新目标并且目标变就更新源)
3:OneTime(只根据源来设置目标,以后都不会变)
4:OneWayToSource(与OneWay相反)
5:Default(可以单向或双向,是靠被值定的源或目标是否有get或set来指定的)
所以绑定的话是需要选上面5个中的一个模式的,根据你的需要来选择,不选的话就会自
动选择第五个的。
或者:
1:OneWay
Source影响着Target,但是Target却影响不到Source。
2:OneWayToSource
Target影响Source,而Source却影响不到Target。
3:TwoWay
Source与Target相互影响。
4:OneTime
在OneWay的基础上延伸了一个OneTime,仅绑定一次。如果大家属性Jquery
中的one函数我想就可以不用表述了。
XAML代码:
1 <Window x:Class="WpfApplication1.Window1"
2
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:sys="clr-namespace:System;assembly=mscorlib"
5 xmlns:src="clr-namespace:WpfApplication1"
6 Title="MainWindow" Height="350" Width="525">
7 <!--页面画布布局-->
8 <Canvas>9 <ScrollBar Height="24" Name="scrollBar1" Width="237"
Orientation="Horizontal" Canvas.Left="103" Canvas.Top="51" Minimum="1"
Maximum="100" SmallChange="1" />
10 <Label Canvas.Left="41" Canvas.Top="121" Content="OneWay"
Height="28" Name="label1" />
11 <!--OneWay 仅当源属性发生更改时更新目标属性。-->
12 <TextBox Canvas.Left="165" Canvas.Top="121" Height="23"
13 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=OneWay}"
14 Name="textBox1" Width="120" />
15 <Label Canvas.Left="41" Canvas.Top="160"
Content="OneWayToSource" Height="28" Name="label2" />
16 <!--OneWayToSource 在目标属性更改时更新源属性。-->
17 <TextBox Canvas.Left="165" Canvas.Top="160" Height="23"
18 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=OneWayToSource}"
19 Name="textBox2" Width="120" />
20 <Label Canvas.Left="41" Canvas.Top="202" Content="TwoWay"
Height="28" Name="label3" />
21 <!--TwoWay 源属性与目标属性相互影响。-->
22 <TextBox Canvas.Left="165" Canvas.Top="202" Height="23"
23 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=TwoWay}"
24 Name="textBox3" Width="120" />
25 <Label Canvas.Left="41" Canvas.Top="231" Content="OneTime"
Height="28" Name="label4" />
26 <!--OneTime 仅当应用程序启动时或 DataContext 进行更改时更新目标属
性。仅绑定一次-->
27 <TextBox Canvas.Left="165" Canvas.Top="231" Height="23"
28 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=OneTime}"
29 Name="textBox4" Width="120" />
30 </Canvas>
31 </Window>
32
效果截图:(可能颜色有点修改不要介意)

1:OneWay(源变就更新目标属性)
2:TwoWay(源变就更新目标并且目标变就更新源)
3:OneTime(只根据源来设置目标,以后都不会变)
4:OneWayToSource(与OneWay相反)
5:Default(可以单向或双向,是靠被值定的源或目标是否有get或set来指定的)
所以绑定的话是需要选上面5个中的一个模式的,根据你的需要来选择,不选的话就会自
动选择第五个的。
或者:
1:OneWay
Source影响着Target,但是Target却影响不到Source。
2:OneWayToSource
Target影响Source,而Source却影响不到Target。
3:TwoWay
Source与Target相互影响。
4:OneTime
在OneWay的基础上延伸了一个OneTime,仅绑定一次。如果大家属性Jquery
中的one函数我想就可以不用表述了。
XAML代码:
1 <Window x:Class="WpfApplication1.Window1"
2
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:sys="clr-namespace:System;assembly=mscorlib"
5 xmlns:src="clr-namespace:WpfApplication1"
6 Title="MainWindow" Height="350" Width="525">
7 <!--页面画布布局-->
8 <Canvas>9 <ScrollBar Height="24" Name="scrollBar1" Width="237"
Orientation="Horizontal" Canvas.Left="103" Canvas.Top="51" Minimum="1"
Maximum="100" SmallChange="1" />
10 <Label Canvas.Left="41" Canvas.Top="121" Content="OneWay"
Height="28" Name="label1" />
11 <!--OneWay 仅当源属性发生更改时更新目标属性。-->
12 <TextBox Canvas.Left="165" Canvas.Top="121" Height="23"
13 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=OneWay}"
14 Name="textBox1" Width="120" />
15 <Label Canvas.Left="41" Canvas.Top="160"
Content="OneWayToSource" Height="28" Name="label2" />
16 <!--OneWayToSource 在目标属性更改时更新源属性。-->
17 <TextBox Canvas.Left="165" Canvas.Top="160" Height="23"
18 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=OneWayToSource}"
19 Name="textBox2" Width="120" />
20 <Label Canvas.Left="41" Canvas.Top="202" Content="TwoWay"
Height="28" Name="label3" />
21 <!--TwoWay 源属性与目标属性相互影响。-->
22 <TextBox Canvas.Left="165" Canvas.Top="202" Height="23"
23 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=TwoWay}"
24 Name="textBox3" Width="120" />
25 <Label Canvas.Left="41" Canvas.Top="231" Content="OneTime"
Height="28" Name="label4" />
26 <!--OneTime 仅当应用程序启动时或 DataContext 进行更改时更新目标属
性。仅绑定一次-->
27 <TextBox Canvas.Left="165" Canvas.Top="231" Height="23"
28 Text="{Binding ElementName=scrollBar1, Path=Value,
Mode=OneTime}"
29 Name="textBox4" Width="120" />
30 </Canvas>
31 </Window>
32
效果截图:(可能颜色有点修改不要介意)
