简体   繁体   English

在DataGrid中已选择的选择行上执行C#WPF执行操作

[英]C# WPF Execute Action on select row that already selected in DataGrid

I am trying to execute an action SelectedItem on row selected with DataGrid . 我试图在使用DataGrid SelectedItem的行上执行动作SelectedItem I have a lot of code so I just put here the relevant parts. 我有很多代码,所以我只把相关部分放在这里。 If you need more information please tell me. 如果您需要更多信息,请告诉我。

When I click the row it's selected and the action is executed. 当我单击该行时,它被选中并执行操作。 It opens another window and lets the user do something there. 它打开另一个窗口,并允许用户在其中执行某项操作。 I also want to let one chose this row again and Action this Set method again, but it's doing nothing until I chose another row and only after I chose another row it lets me get the first row. 我也想让一个人再次选择该行,然后再次操作此Set方法,但是在选择另一行之前,它什么都不做,只有在选择另一行之后,它才让我得到第一行。

In short, I want to be able to execute an action on selecting row1 and then execute it again on selecting row1 again. 简而言之,我希望能够在选择row1执行一个动作,然后在再次选择row1再次执行它。

My XAML code: 我的XAML代码:

<DataGrid IsReadOnly="True" Name="DataGridProject" ItemsSource="{Binding ProjectList}"
AutoGenerateColumns="False" FontSize="22"
SelectedItem="{Binding SelectedRowItem,Mode=TwoWay}" DockPanel.Dock="Bottom" MaxHeight="300"
MinHeight="350" Height="350" SelectionMode="Single"/>

My ModelView Code: 我的ModelView代码:

public class PreTestInformationProjectAccessVM : INotifyPropertyChanged
{
    public DataRowView SelectedRowItem
    {
        get
        {
            return _SelectedRowItem;
        }
        set
        {
            _SelectedRowItem = value;
             // ...        
        }
    }
}

Select current item can't Trigger selectedItem changed event,you can try mouse events like: 选择当前项目无法触发selectedItem更改事件,可以尝试以下鼠标事件:

<DataGrid.RowStyle>
     <Style TargetType="DataGridRow">
           <EventSetter Event="MouseDown"  Handler="Click_Do" />
     </Style>
</DataGrid.RowStyle>

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

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