【问题标题】:How to attach the alpha value of an element to a slider?如何将元素的 alpha 值附加到滑块?
【发布时间】:2010-10-07 03:30:58
【问题描述】:

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

例如,这是允许滑块改变元素的高度和顶部位置的代码,但是在边框的背景属性中控制 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>

【问题讨论】:

    标签: wpf binding


    【解决方案1】:

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

    【讨论】:

    • 亚当,你能告诉我们你看到了什么反应吗?不透明度是否突然从完全不透明变为完全透明?如果是这样,请尝试将滑块上的 SmallChange 属性设置为“0.05”,将 LargeChange 设置为“0.2”。看看有没有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 2021-04-18
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多