如何将元素的alpha值附加到滑块?

时间:2009-02-12 10:33:01

标签: wpf binding

是否可以将元素的alpha值绑定到滑块?

例如,这是允许滑块更改元素的高度和顶部位置的代码,但是控制边框的Background属性中的alpha值的语法是什么?

<Window x:Class="WpfApplication25.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid Background="Tan">
        <StackPanel>
            <Canvas>
                <Border Background="#{Binding ElementName=theSlider, Path=Value}ffff00" 
            Canvas.Left="40" 
            Canvas.Top="{Binding ElementName=theSlider, Path=Value}" 
            CornerRadius="5" 
            BorderBrush="Brown"
            BorderThickness="1"
            >
                    <Rectangle 
            Height="{Binding ElementName=theSlider, Path=Value}"
            Width="50"
            />
                </Border>
            </Canvas>
        </StackPanel>

        <Slider Name="theSlider" HorizontalAlignment="Left" Width="200" Minimum="10" Maximum="200" Cursor="Hand"/>

    </Grid>
</Window>

1 个答案:

答案 0 :(得分:1)

绑定到“不透明度”属性,不要忘记将滑块最小值设置为0,最大值设置为1