用于通过EventTrigger传递ObservableCollection的按钮

时间:2015-08-04 10:05:43

标签: c# xaml button observablecollection eventtrigger

我很难通过ObservableCollection<Content>Button传递给EventTrigger。 现在我在我的xaml中有这样的代码:

 <Button Name="SendListButton" Content="Go" HorizontalAlignment="Left" Margin="725,737,0,0" VerticalAlignment="Top" Width="75" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <command:EventToCommand Command="{Binding SendContent}"  
                        CommandParameter="{Binding  ElementName=SendListButton}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>

在我的MainViewModel.cs中,我有:

public class MainViewModel : ViewModelBase,IMainViewModel
    {
public ICommand SendContent { get; set; }
public ObservableCollection<Content> ContentsToTransfer { get; set; }

public MainViewModel()
        {
            SendContent = new RelayCommand(OnSendContent);

            ContentsToTransfer = new ObservableCollection<Content>();
        }

private void OnSendContent(ObservableCollection<Content> ContentsToTransfer)
        {
            if (ContentsToTransfer.Any())
            {
                //Code executed by the button. 
            }
        }

你能帮我解释一下如何通过EventTrigger传递我的ObeservableCollection以便将其内容发送到数据库吗?

THX!

0 个答案:

没有答案