我从SelectedItems
获取DataGrid
时遇到问题。
这是我的DataGrid
。我已设置SelectionMode=Extended
,以便我可以检索所有选定的项目。
<DataGrid Name="ConcentratorGrid"
SelectionMode="Extended"
SelectedItem="{Binding SelectedSettings, Mode=OneWayToSource}"
ItemsSource="{Binding Concentrators}"
>
SelectedItem
绑定到此:
public ConcentratorSettings SelectedSettings
{
get { return _selectedSettings; }
set
{
if (Equals(value, _selectedSettings)) return;
_selectedSettings = value;
NotifyOfPropertyChange(() => SelectedSettings);
}
}
而ItemSource
就是这个
public ObservableCollection<ConcentratorSettings> Concentrators { get; set; }
现在我想通过单击按钮触发并获取SelectedItems
,我无法使用以下Caliburn.Micro
语法执行此操作。
<Button DockPanel.Dock="Right">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="UploadToConcentrators">
<cal:Parameter Value="{Binding ElementName=ConcentratorGrid, Path=SelectedItems}" />
</cal:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
此按钮使用的方法是第一个作为警卫
public bool CanUploadToConcentrators(IList concentrators)
{
return concentrators?.Count > 0;
}
public void UploadToConcentrators(IList concentrators)
{}
我希望有人知道如何在不使用Command的情况下将selectedItems提供给该方法。
PS。这是我在StackOverFlow上的第一篇文章,所以如果这个信息不够,请告诉我。