简介:
Slider与TextBox的数值绑定,可以在Slider绑定,亦可在TextBox绑定。
使用
Default | 0 | 绑定目标属性的默认 UpdateSourceTrigger 值。 大多数依赖属性的默认值为 PropertyChanged,而 Text 属性的默认值为 LostFocus。确定依赖属性的默认 |
Explicit | 3 | 仅在调用 UpdateSource() 方法时更新绑定源。 |
LostFocus | 2 | 每当绑定目标元素失去焦点时,都会更新绑定源。 |
PropertyChanged | 1 | 每当绑定目标属性发生更改时,都会更新绑定源。 |
1.TextBox绑定,注意UpdateSourceTrigger=PropertyChanged,Mode=TwoWay。
<Slider x:Name="slider" Maximum="100" IsSnapToTickEnabled="True" ></Slider>
<TextBox x:Name="tbx" FontSize="{Binding ElementName=slider,Path=Value}"
Text="{Binding ElementName=slider,Path=Value,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" >
</TextBox>
2.Slider绑定, IsSnapToTickEnabled="True"时数据为整数。
<Slider x:Name="slider" Maximum="100" IsSnapToTickEnabled="True" Value="{Binding ElementName=tbx,Path=Text}"></Slider>
<TextBox x:Name="tbx" FontSize="{Binding ElementName=slider,Path=Value}" ></TextBox>