如何将slider.value绑定到椭圆渐变起始点

时间:2014-02-20 07:06:07

标签: c# wpf xaml binding blend

1 个答案:

答案 0 :(得分:2)

<StackPanel>
    <Ellipse x:Name="ell" Width="50" Height="50">
        <Ellipse.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop x:Name="stopToBind" Color="#FFFF0808" Offset="1"/>
            </LinearGradientBrush>
        </Ellipse.Fill>
    </Ellipse>

    <Slider Value="{Binding ElementName=stopToBind, Path=Offset, Mode=TwoWay}"/>
</StackPanel>

<强>更新

没有顺利:

<StackPanel>
    <Ellipse x:Name="ell" Width="50" Height="50">
        <Ellipse.Fill>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <GradientStop Color="Red" Offset="{Binding ElementName=sl, Path=Value, Mode=TwoWay}"/>
                <GradientStop Color="Black" Offset="{Binding ElementName=sl, Path=Value, Mode=TwoWay}"/>
            </LinearGradientBrush>
        </Ellipse.Fill>

    </Ellipse>

    <Slider Value="0.5" x:Name="sl" Maximum="1" Minimum="0"/>
</StackPanel>