C# 不带代码begind的datagrid行详细信息

C# 不带代码begind的datagrid行详细信息,c#,wpf,datagrid,C#,Wpf,Datagrid,我想在选中复选框后显示行详细信息,如果未选中,则将其折叠。我也不想使用codebehind。我知道存在使用转换器的解决方案。对于我正在使用的事件触发器 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 但它不起作用。选中复选框后,行详细信息不起作用。我认为可视化树中的不同

我想在选中复选框后显示行详细信息,如果未选中,则将其折叠。我也不想使用codebehind。我知道存在使用转换器的解决方案。对于我正在使用的事件触发器

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
但它不起作用。选中复选框后,行详细信息不起作用。我认为可视化树中的不同分支存在问题

namespace WpfApplication9
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new Data();
    }
}
public class Emloyee
{
    public string FirstName{ get; set; }

    public string LastName { get; set; }

    public string ID { get; set; }

    public double Sallary { get; set; }

}
public class Data
{
    public ObservableCollection<Emloyee> Items { get; set; }
    public Data()
    {
        Items = new ObservableCollection<Emloyee>();
        Items.Add(new Emloyee { FirstName="Jhon",ID="1",LastName="Smith",Sallary=100});
        Items.Add(new Emloyee { FirstName="Neo",ID="0",LastName="Neo",Sallary=0});
    }
}
}
命名空间WpfApplication9
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
DataContext=新数据();
}
}
公共级埃姆洛伊酒店
{
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串ID{get;set;}
公共双数组{get;set;}
}
公共类数据
{
公共ObservableCollection项{get;set;}
公共数据()
{
Items=新的ObservableCollection();
添加(新的Emloyee{FirstName=“Jhon”,ID=“1”,LastName=“Smith”,Sallary=100});
添加(新的Emloyee{FirstName=“Neo”,ID=“0”,LastName=“Neo”,Sallary=0});
}
}
}
Xaml


在触发器中:

<i:EventTrigger EventName="Checked">
    <ei:ChangePropertyAction TargetName="ShowGrid" PropertyName="DetailsVisibility" Value="Visible"/>
</i:EventTrigger>
<i:EventTrigger EventName="Checked">
    <ei:ChangePropertyAction TargetName="ShowGrid" PropertyName="DetailsVisibility" Value="Visible"/>
</i:EventTrigger>
<Window.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</Window.Resources>
<!-- ... -->
<DataGridTemplateColumn Width="10">
    <DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <Label HorizontalContentAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" VerticalContentAlignment="Center"/>
        </DataTemplate>
    </DataGridTemplateColumn.HeaderTemplate>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox VerticalAlignment="Center" HorizontalAlignment="Center"
                      Checked="{Binding DetailsVisibility,
                                        Mode=TwoWay,
                                        RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},
                                        Converter={StaticResource BooleanToVisibilityConverter}}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>