0

The event binding of Caliburn.Micro seems not to work with the ListPickerFlyout of Windows Phone 8.1. I want to bind the event ItemsPicked of the Flyout to the corresponding method of my 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>

When the event will be raised, I get the following exception: No target found for method ItemsPicked.

System.Exception: No target found for method ItemsPicked. at Caliburn.Micro.ActionMessage.Invoke(Object eventArgs) at Caliburn.Micro.TriggerAction`1.Execute(Object sender, Object parameter) at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter) at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)

I also tried it without event and method method parameters but it does not work either.

zirkelc
  • 1,451
  • 1
  • 23
  • 49

1 Answers1

0

The problem occured becouse ListPickerFlyout doesn't have DataContext (or has wrong). I don't see a way to set the DataContext, but you can determine selected item by pinning to setter of your SelectedList property from ViewModel. For example if your SelectedList is type of string:

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

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

            NotifyOfPropertyChange(() => SelectedLists);
        }
    }

    private void ItemsPicked(string selectedValue)
    {
        //Handle selection
    }
marcinax
  • 1,067
  • 7
  • 10
  • Datacontext is inherited from the object from which its attached. FlyoutBase.AttachedFlyout or `` as an example... https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn308515.aspx – mvermef Oct 16 '15 at 22:41
  • While it is part of the problem not knowing how he setup the ListPickerFlyout to begin with from a coding standing point it shouldn't be a allowed to free stand on the screen since it is a Flyout, has to be attached in some fashion. We don't have the whole picture in this instance presently. – mvermef Oct 16 '15 at 22:46
  • The ListPickerFlyout is attachted a ListView control. – zirkelc Oct 17 '15 at 12:25