[英]C# WPF Execute Action on select row that already selected in DataGrid
我試圖在使用DataGrid
SelectedItem
的行上執行動作SelectedItem
。 我有很多代碼,所以我只把相關部分放在這里。 如果您需要更多信息,請告訴我。
當我單擊該行時,它被選中並執行操作。 它打開另一個窗口,並允許用戶在其中執行某項操作。 我也想讓一個人再次選擇該行,然后再次操作此Set
方法,但是在選擇另一行之前,它什么都不做,只有在選擇另一行之后,它才讓我得到第一行。
簡而言之,我希望能夠在選擇row1
執行一個動作,然后在再次選擇row1
再次執行它。
我的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"/>
我的ModelView代碼:
public class PreTestInformationProjectAccessVM : INotifyPropertyChanged
{
public DataRowView SelectedRowItem
{
get
{
return _SelectedRowItem;
}
set
{
_SelectedRowItem = value;
// ...
}
}
}
選擇當前項目無法觸發selectedItem更改事件,可以嘗試以下鼠標事件:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseDown" Handler="Click_Do" />
</Style>
</DataGrid.RowStyle>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.