简体   繁体   English

Silverlight DataGrid上的绑定问题

[英]Binding issue on silverlight datagrid

I have a datagrid on which I want to bind the foreground colour of a column like so : 我有一个数据网格,我想像这样绑定一列的前景色:

<sdk:DataGridTextColumn Header="Bid Qty" Binding="{Binding Path=BidPrice.QuantityString}" Foreground="{Binding BidPrice.TextColour}" />

But I am getting this error in the form init : 但是我以init的形式出现此错误:

Set property 'System.Windows.Controls.DataGridTextColumn.Foreground' threw an exception. [Line: 95 Position: 106]

Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.Windows.Media.Brush'.

I tried setting the type of TextColour to be SolidColorBrush but that did not help. 我尝试将TextColour的类型设置为SolidColorBrush,但这没有帮助。

EDIT: 编辑:

Bid price is a type of product price : 买价是产品价格的一种:

    public class ProductPrice
    {
        public SolidColorBrush TextColour { get; set; }
}

And set like so : 并设置为:

private void SetColours(ProductPrice price, string firmPriceColour = "Black", string impliedPriceColour = "Black")
{
    if (price != null)
    {
        if (price.IsImplied.GetValueOrDefault(false))
            price.TextColour = ColourHelper.StringToColorBrush(impliedPriceColour);
        else
            price.TextColour = ColourHelper.StringToColorBrush(firmPriceColour);
    }
}

Note it could possible be null. 注意它可能为空。

Create a SolidColorBrush and bind BidPrice.TextColour to it's Color property. 创建一个SolidColorBrush并将BidPrice.TextColour绑定到它的Color属性。 Then bind DataGridTextColumn.Foreground to that brush. 然后将DataGridTextColumn.Foreground绑定到该画笔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM