首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wpf将椭圆梯度停止颜色绑定到ellipse变频器上

wpf将椭圆梯度停止颜色绑定到ellipse变频器上
EN

Stack Overflow用户
提问于 2015-09-14 07:43:47
回答 2查看 785关注 0票数 0

我有一个椭圆绑定到一个复选框和一个iValueConverter (,这是工作的.填写(见下文)。

代码语言:javascript
复制
 <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呢?

代码语言:javascript
复制
<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>

请帮帮忙。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-14 07:56:17

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

票数 1
EN

Stack Overflow用户

发布于 2015-09-14 08:07:08

您的转换器应该返回一个LinearGradientBrush而不是SolidColorBrush,并保持原样。

代码语言:javascript
复制
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

代码语言:javascript
复制
 <Ellipse Name="ellLeftRoleEnabled" 
             Fill="{Binding IsChecked, ElementName=btnRollLeftEnabled, Converter={StaticResource myColorConverter}}" 
             Height="80" Canvas.Left="355" Stroke="#FF0C703E" Canvas.Top="440" Width="80"/>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32559565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档