DataGridCell获取绑定值

时间:2014-08-28 13:42:26

标签: c# binding styles converter datagridcell

我尝试将单元格内容作为一个类,例如我绑定 我怎么能这样做?

<Style TargetType="{x:Type DataGridCell}">
                    <Style.Triggers >
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content, Converter={StaticResource MyConverter}}" Value="1">
                            <Setter Property="Margin" Value="15,0,0,0" />
                        </DataTrigger>
 </Style.Triggers>
</Style>

这里是Converter类:

 public class MyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value!= null)
            {
                //to do  value is TextBlcock and I cant get value need I
            }
            return  value;
        }
    }

1 个答案:

答案 0 :(得分:0)

我找到了解决方案here。最好的解决方案似乎是

DataGridRow发送到转换器

 <MultiBinding Converter="{StaticResource MyConverter}" Mode="OneWay">
                                    <Binding Path="." RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridRow}" />
                                    <Binding Path="." RelativeSource="{RelativeSource Self}"/>
                                </MultiBinding>