您可以测试所选项目是否为空,这只是一种可能帮助您 XAML 的方法:
<Custom1:DataGrid IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<Custom:EventToCommand CommandParameter="{Binding SelectedItem, ElementName=dg}" Command="{Binding AfficheCommand, Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
后面的代码:
private PersonModel _selectedPersons = new PersonModel();
public PersonModel SelectedPerson
{
set
{
_selectedPersons = value;
}
}
public ICommand AfficheCommand
{
get
{
return new DelegateCommand(AfficheText);
}
}
private void AfficheText()
{
if(_selectedPersons != null)
MessageBox.Show(_selectedPersons.FirstName);
_selectedPersons = null;
}
我知道这不是最好的方法,而是一种方法,直到您找到更好的主意;)