如何将SelectedItems作为列表添加到Caliburn.Micro中的ViewModel

时间:2016-03-08 07:29:13

标签: c# xaml mvvm datagrid caliburn.micro

我从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上的第一篇文章,所以如果这个信息不够,请告诉我。

0 个答案:

没有答案