如何:将滑块绑定到属性值
更新:2007 年 11 月
此示例演示如何将 Rectangle 的 Height 属性绑定到 Slider 控件的 Value。
示例
下面的示例演示如何定义名为 RectangeHeight 的 Slider 控件,该控件可以具有介于 0 和 200 之间的 Value。
<Slider Name="RectangleHeight" Margin="10, 0, 0, 0"
Width="100" Orientation="Horizontal" HorizontalAlignment="Left"
Value="50" Minimum="0" Maximum="200"
SmallChange="1" LargeChange="10"
TickPlacement="BottomRight" TickFrequency="10"/>
下面的示例演示如何定义将其 Height 属性绑定到 Slider 控件的 Value 的 Rectangle。(在完整的示例中,为 Width 属性创建了一个类似的绑定。)
<Rectangle Fill="Blue" HorizontalAlignment="Left"
Margin="50,20,0,0"
Height="{Binding ElementName=RectangleHeight,Path=Value}"
Width="{Binding ElementName=RectangleWidth,Path=Value}"/>
有关完整示例,请参见 具有数据绑定的滑块的示例。