0

我已经将一个椭圆绑定到一个复选框和一个 iValueConverter (这有效 ......填充(见下文))。

 <Ellipse Name="ellLeftRoleEnabled" 
                 Fill="{Binding IsChecked, ElementName=btnRollLeftEnabled, Converter={StaticResource myColorConverter}}" 
                 Height="80" Canvas.Left="355" Stroke="#FF0C703E" Canvas.Top="440" Width="80"/>

但是现在,我如何将它用于 LinearGradientBrush/GradientStop?

<Ellipse Name="ellLeftRoleMoving" Height="100" Canvas.Left="345" Stroke="Black" Canvas.Top="535" Width="100">
            <Ellipse.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="{?????} Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Ellipse.Fill>
        </Ellipse>

请帮忙。谢谢你。

4

2 回答 2

1

当将它用于 GradientStop 颜色的颜色时,您不应该像第一个转换器那样返回画笔,而是返回颜色。其余的都是一样的。

于 2015-09-14T07:56:17.863 回答
1

您的转换器应返回 aLinearGradientBrush而不是 aSolidColorBrush并保持 xaml 原样

public class myColorConverter:IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((bool) value)
            ? new LinearGradientBrush()
            {
                EndPoint = new Point(0.5, 1),
                StartPoint = new Point(0.5, 0),
                GradientStops = new GradientStopCollection()
                {
                    new GradientStop(Colors.Red, 0),
                    new GradientStop(Colors.White, 1)
                }
            }
            : new LinearGradientBrush()
            {
                EndPoint = new Point(0.5, 1),
                StartPoint = new Point(0.5, 0),
                GradientStops = new GradientStopCollection()
                {
                    new GradientStop(Colors.Blue, 0),
                    new GradientStop(Colors.Red, 1)
                }
            };
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Xaml

 <Ellipse Name="ellLeftRoleEnabled" 
             Fill="{Binding IsChecked, ElementName=btnRollLeftEnabled, Converter={StaticResource myColorConverter}}" 
             Height="80" Canvas.Left="355" Stroke="#FF0C703E" Canvas.Top="440" Width="80"/>
于 2015-09-14T08:07:08.910 回答