WinRT CaliburnMicro事件绑定到ListPickerFlyout

时间:2015-10-16 15:27:25

标签: c# windows-phone-8.1 winrt-xaml caliburn.micro flyout

Caliburn.Micro的事件绑定似乎不适用于Windows Phone 8.1的 ListPickerFlyout 。我想将Flyout的事件 ItemsPicked 绑定到我的ViewModel的相应方法。

    <ListView 
            x:Name="Links"
            toolkitex:ListViewExtensions.BindableSelection="{Binding Selection}"
            cm:Message.Attach="[Event ItemClick] = [Click($link)]">

        <FlyoutBase.AttachedFlyout>
            <ListPickerFlyout 
                SelectionMode="Single"
                Placement="Full"
                ItemsSource="{Binding Lists}"
                SelectedItem="{Binding SelectedList, Mode=TwoWay}"
                ctrls:FlyoutEx.Parent="{Binding ElementName=Links}"
                ctrls:FlyoutEx.IsOpen="{Binding IsListSelectionOpen, Mode=TwoWay}"
                cm:Message.Attach="[Event ItemsPicked] = [ItemsPicked($this, $eventArgs)]">
            </ListPickerFlyout>
        </FlyoutBase.AttachedFlyout>
    </ListView>

当引发事件时,我会收到以下异常:找不到方法ItemsPicked的目标。

  

System.Exception:找不到方法ItemsPicked的目标。          at Caliburn.Micro.ActionMessage.Invoke(Object eventArgs)          at Caliburn.Micro.TriggerAction`1.Execute(Object sender,Object parameter)          在Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(对象发送者,   ActionCollection动作,Object参数)          在Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object   sender,Object eventArgs)

我也尝试过没有事件和方法方法参数,但它也不起作用。

1 个答案:

答案 0 :(得分:0)

问题发生因为ListPickerFlyout没有DataContext(或有错误)。我没有看到设置DataContext的方法,但您可以通过固定到ViewModel的SelectedList属性的setter来确定所选项目。例如,如果您的SelectedList类型为string

    private string _selectedLists;
    public string SelectedLists
    {
        get { return _selectedLists; }
        set
        {
            _selectedLists = value;

            ItemsPicked(value); // <----------------

            NotifyOfPropertyChange(() => SelectedLists);
        }
    }

    private void ItemsPicked(string selectedValue)
    {
        //Handle selection
    }