我有一个椭圆绑定到一个复选框和一个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>请帮帮忙。谢谢。
发布于 2015-09-14 07:56:17
当将它用于GradientStop颜色时,您不应该返回像第一个转换器那样的画笔,而应该返回颜色。其余的都一样。
发布于 2015-09-14 08:07:08
您的转换器应该返回一个LinearGradientBrush而不是SolidColorBrush,并保持原样。
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"/>https://stackoverflow.com/questions/32559565
复制相似问题