请问为什么这样子绑定信息,没有文字的颜色没有发生变化

weixin_38056418 2016-09-05 03:54:25
 <DataGridTemplateColumn MinWidth="80" Header="最新价">
                            <DataGridTemplateColumn.CellStyle>
                                <Style TargetType="DataGridCell">
                                    <Setter Property="Background" Value="Yellow"/>
                                    <Setter Property="Foreground" >
                                        <Setter.Value>
                                            <MultiBinding Converter="{StaticResource LatestPriceFrocegroundConverter}">
                                                <Binding Path="LatestPrice"/>
                                                <Binding Path="EarlyMorning"/>
                                            </MultiBinding>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </DataGridTemplateColumn.CellStyle>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding LatestPrice}"  >
                                        <!--<TextBlock.Foreground>
                                            <MultiBinding Converter="{StaticResource LatestPriceFrocegroundConverter}">
                                                <Binding Path="LatestPrice"/>
                                                <Binding Path="EarlyMorning"/>
                                            </MultiBinding>
                                        </TextBlock.Foreground>-->
                                    </TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

/// <summary>
    /// 最新价文字颜色转换器
    /// 当最新价大于开盘价时为红色
    /// 当最新价小于开盘价时为绿色
    /// 当最新价等于开盘价时为白色
    /// </summary>
    class LatestPriceFrocegroundConverter : IMultiValueConverter
    {

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[0] == null || values[1] == null)
            {
                return null;
            }
            double temp = 0;
            double d1 = 0;
            double d2 = 0;
            if (double.TryParse(values[0].ToString(), out temp))
            {
                d1 = temp;
            }
            else
            {
                return null;
            }
            if (double.TryParse(values[1].ToString(), out temp))
            {
                d2 = temp;
            }
            else
            {
                return null;
            }

            if (d1 > d2)
            {
                return Color.Red;
            }
            else if (d1 < d2)
            {
                return Color.Green;
            }
            else
            {
                return Color.White;
            }
            //return "Gold";
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
...全文
16 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧