C# ValueConverter方法已命中,但未显示在UI上

C# ValueConverter方法已命中,但未显示在UI上,c#,xaml,xamarin,valueconverter,C#,Xaml,Xamarin,Valueconverter,我有一张发票清单。这些发票的方向值由int表示(传入=0,发出=1)。我想按列表中的颜色区分这些发票 我尝试使用ValueConverter,但当我用发票填充列表时,它不起作用,背景颜色保持默认颜色,即使我在其中放置断点时,ValueConvert方法被命中,它会从列表中恢复所有对象。如果我将边界替换为xaml文件中的任何颜色,它将起作用,并且背景将更改为特定颜色 我错过了什么 我的xaml(仅包含相关代码): 正如Jason在评论中提到的,您应该返回颜色类型,而不是画笔类型 class Inv

我有一张发票清单。这些发票的方向值由int表示(传入=0,发出=1)。我想按列表中的颜色区分这些发票

我尝试使用ValueConverter,但当我用发票填充列表时,它不起作用,背景颜色保持默认颜色,即使我在其中放置断点时,ValueConvert方法被命中,它会从列表中恢复所有对象。如果我将边界替换为xaml文件中的任何颜色,它将起作用,并且背景将更改为特定颜色

我错过了什么

我的xaml(仅包含相关代码):


正如Jason在评论中提到的,您应该返回
颜色
类型,而不是
画笔
类型

class InvoiceDirectionColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        int invoicedirection = (int)value;
        if (invoicedirection != null && invoicedirection.Equals(0))
        {
            return Color.Green;
        }
        else
        {
            return Color.Yellow;
        }
    }

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

你应该返回一种颜色,而不是画笔哦,我错过了。非常感谢,它很有效!
class InvoiceDirectionColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        SolidColorBrush brush = new SolidColorBrush();
        int invoicedirection = (int)value;
        if (invoicedirection != null && invoicedirection.Equals(0))
        {
            brush.Color = Color.Green;
        }
        else
        {
            brush.Color = Color.Yellow;
        }
        return brush;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
class InvoiceDirectionColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        int invoicedirection = (int)value;
        if (invoicedirection != null && invoicedirection.Equals(0))
        {
            return Color.Green;
        }
        else
        {
            return Color.Yellow;
        }
    }

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