Wpf DataGrid RowStyle-DataTrigger中的绑定值

Wpf DataGrid RowStyle-DataTrigger中的绑定值,wpf,vb.net,xaml,wpfdatagrid,Wpf,Vb.net,Xaml,Wpfdatagrid,我想构建一个行样式,它根据两个条件(或)更改行的可见性 默认情况下,无论布尔值(在ViewModel中)设置为True,还是绑定到Datagrid的DataTable中的值等于当前用户,所有行都应折叠并可见。因此,当前用户当然也是一个属性 <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="Visibility" Value="Coll

我想构建一个
行样式
,它根据两个条件(或)更改行的
可见性

默认情况下,无论布尔值(在ViewModel中)设置为
True
,还是绑定到
Datagrid
DataTable
中的值等于当前用户,所有行都应折叠并可见。因此,当前用户当然也是一个属性

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
        <Setter Property="Visibility" Value="Collapsed" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window},Mode=FindAncestor},Path=DataContext.ColleaguesVisible}" Value="True">
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>
            <DataTrigger Binding="{Binding CreatingUser}" Value="{Binding CurrentStaffMember}">
                <Setter Property="Visibility" Value="Visible" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

但是在值绑定中有一个错误

我已经到处找过了,但找不到解决这个问题的办法


我希望有人能帮我。

CreatingUser在哪里?在行DataContext(您的项目)中,或在DataGrid后面的ViewModel中,或在窗口后面的ViewModel中

也许这就是你的问题?

你不能将
属性绑定到
数据触发器
上,因为它不是依赖属性

您可以使用转换器:

<DataGrid ... x:Name="dgr" xmlns:local="clr-namespace:WpfApp2">
    <DataGrid.Resources>
        <local:Converter x:Key="conv" />
    </DataGrid.Resources>
    <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <Setter Property="Visibility" Value="Collapsed" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window},Mode=FindAncestor},Path=DataContext.ColleaguesVisible}" Value="True">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=., Converter={StaticResource conv}}" Value="True">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>

谢谢,正是我需要的。无论如何,我将Userstuff移到了
DataRowView.Filter
,但在我还需要的
按钮中使用了它。
namespace WpfApp2
{
    public class Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DataRowView drv = value as DataRowView;
            if(drv != null)
            {
                return drv["CreatingUser"].ToString() == drv["CurrentStaffMember"].ToString();
            }
            return false;
        }

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