简体   繁体   English

c#wpf DataGridCell从转换器设置值

[英]c# wpf DataGridCell set value from convertor

I have this DataGridCell and it calls this converter. 我有这个DataGridCell,它叫做这个转换器。 I was expecting the value of this cell to be "hi" (as I'm setting the cell "content" to "hi") when its shown in the datagrid after going through the convertor. 我曾期望此单元格的值是“ hi”(因为我正在将单元格“ content”设置为“ hi”),当它在通过转换器后显示在datagrid中时。

What am I doing wrong here? 我在这里做错了什么?

<DataGridTextColumn Width="60" Header="Google" CanUserResize="True" CanUserSort="True">
    <DataGridTextColumn.HeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="ToolTip" Value="Current Position on Google" />
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>
    </DataGridTextColumn.HeaderStyle>
    <DataGridTextColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <EventSetter Event="MouseUp" Handler="IdUnselect"/>

            <Setter Property="Background"   Value="{Binding GoogleKeywordPositionMovementSinceLastWeekCheck, Converter={StaticResource NameToBrushConverter}}"/>
            <Setter Property="Content"      Value="{Binding Path=., Converter={StaticResource GooglePositionConvertor}}"/>

        </Style>
    </DataGridTextColumn.CellStyle>

</DataGridTextColumn>



public class GooglePositionConvertor : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        ResultCheckObject RankCheck = value as ResultCheckObject;

        return "hi";
    }

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

Setting the content through a converter in the way below did not work. 无法通过以下方式通过转换器设置内容。

<Setter Property="Content" Value="{Binding Path=., Converter={StaticResource GooglePositionConvertor}}"/>

Setting it through a converter as below worked 通过转换器进行如下设置

<DataGridTextColumn Width="60" Header="Google" Binding="{Binding Path=., Converter={StaticResource GooglePositionConvertor}}" CanUserResize="True" CanUserSort="True">

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

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