C# WPF datagrid.rowstyle绑定

C# WPF datagrid.rowstyle绑定,c#,wpf,mvvm,binding,datagrid,C#,Wpf,Mvvm,Binding,Datagrid,我有一个已知的错误 System.Windows.Data错误:2:找不到目标元素的治理FrameworkElement或FrameworkContentElement。BindingExpression:路径=百分比;DataItem=null;目标元素是“GradientStop”(HashCode=81530);目标属性为“偏移量”(类型为“双精度”) 关于代码的这一部分: <DataGrid.RowStyle> <Style Ta

我有一个已知的错误

System.Windows.Data错误:2:找不到目标元素的治理FrameworkElement或FrameworkContentElement。BindingExpression:路径=百分比;DataItem=null;目标元素是“GradientStop”(HashCode=81530);目标属性为“偏移量”(类型为“双精度”)

关于代码的这一部分:

        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding State}" Value="Started">
                        <Setter Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                                    <GradientStop Color="Green" Offset="0" />
                                    <GradientStop Color="#FF2D2D30" Offset="{Binding Percent}" />
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                    <Trigger Property="Validation.HasError" Value="true">
                        <Setter Property="BorderThickness" Value="1"/>
                        <Setter Property="BorderBrush" Value="Red"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>
System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ViewModel”(HashCode=37637549)“上找不到“百分比”属性。BindingExpression:Path=Data.Percent;DataItem='BindingProxy'(HashCode=3342738);目标元素为“GradientStop”(HashCode=64874797);目标属性为“偏移量”(类型为“双精度”)

这一点很明显,因为数据现在包含控件(即我的ViewModel)的DataContext


有什么建议吗?谢谢

正如其他帖子所建议的,我认为这不适用于我的问题,但使用转换器非常合适!以下是一些参考资料:

还有XAML

<UserControl.Resources>
   <app:GradientProgressConverter  x:Key="GradientProgressConverter" />
</UserControl.Resources>
<DataGrid>
   <DataGrid.RowStyle>
      <Style TargetType="DataGridRow">
         <Style.Triggers>
            <DataTrigger Binding="{Binding State}" Value="Started">
                <Setter Property="Background" Value="{Binding Converter={StaticResource GradientProgressConverter}}" />
            </DataTrigger>
         </Style.Triggers>
      </Style>
   </DataGrid.RowStyle>
</<DataGrid>

    public object Convert(object value, Type targetType, object parameter,
        System.Globalization.CultureInfo culture)
    {
        Model.ListParameters parameters = (Model.ListParameters)value;
        if(parameters !=null)
        {
            var start = new GradientStop();
            start.Color = Colors.Green;
            start.Offset = 0;

            var stop = new GradientStop();
            stop.Color = (Color)ColorConverter.ConvertFromString("#FF2D2D30");
            stop.Offset = parameters .Percent;

            var result = new LinearGradientBrush();
            result.StartPoint = new Point(0, 0);
            result.EndPoint = new Point(1, 0);
            result.GradientStops.Add(start);
            result.GradientStops.Add(stop);

            return result;
        }
        return null;
    }
<UserControl.Resources>
   <app:GradientProgressConverter  x:Key="GradientProgressConverter" />
</UserControl.Resources>
<DataGrid>
   <DataGrid.RowStyle>
      <Style TargetType="DataGridRow">
         <Style.Triggers>
            <DataTrigger Binding="{Binding State}" Value="Started">
                <Setter Property="Background" Value="{Binding Converter={StaticResource GradientProgressConverter}}" />
            </DataTrigger>
         </Style.Triggers>
      </Style>
   </DataGrid.RowStyle>
</<DataGrid>