This project is read-only.

ContactPicker

Sep 1, 2012 at 6:34 PM

I'm trying to impement ContactPicker. It doesn't seem to be implemented yet in the BootStrapper, so I've added the OnActivated override to the App.cs but my ViewModel is not fired when my contact picker page is launched.

Am I missing something? Do I need to do something in the OnActivated in my App.cs in order to initialize the framework since the OnActivated can be run even though the app is not running?


Sep 3, 2012 at 6:07 AM

Andy, would you mind giving a quick example of how to implement the contact picker?

If I use the OnActivated from the applicationbootstrapper it doesn't fire when the contact picker launches. If I add the OnActivated to the App.cs I get is launched and I can launch my search page, but the ViewModel doesn't seem to get called with the page. I'm not sure what I'm doing wrong.

 

Sep 3, 2012 at 10:46 AM

I was having a look at the startup path for the FileOpenPicker (which is a hosted view the same as for the ContactPicker) and things get a bit more complicated here. As you have noted, the bootstrapper only picks up activation events from the application's main CoreApplicationView, whilst the pickers create a dedicated view and raise the activation events there. For the moment the best approach is to use the OnXxxActivated(...) method of the App,cs file as you have found.

The second issue is that the Okra NavigationManager (which normally handles creation of views & view-models) is a singleton and dedicated to the main application view. I am aiming to add support for multiple navigation stacks, but this will be a future version.

Is there a requirement for any form of navigation within your contact picker, or is it a single page with a GridView? If it is the latter then you should be able to wire everything up by hand in the Application.OnActivated() method rather than rely on Okra.

protected override OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ...)
    {
        MyView view = new MyView();
        MyViewModel vm = new MyViewModel();

        view.DataContext = vm;

        Window.Current.Content = view;
        Window.Current.Activate();
    }
}

Obviously insert the relevant ActivationKind as required. Unfortunately you don't get the extra Okra injected events etc., but for simple cases should work. You also don't get the MEF composition either so if you are relying on that then you need to get MEF to compose the view/view-model rather than using the constructor. Ultimately I'd like to get this into the Okra App Framework as a supported activation type, but for the moment the manual workaround is best.

Regards,

    Andy

Sep 3, 2012 at 4:46 PM

Thanks Andy,

this does work, however when I close the contact picker I'm getting an exception that "The operation cannot be completed because the window is being closed".

I'm using a IncrementalLoadingDataList as my source for my GridView and I'm experiencing some major performance issue and exceptions with it.

I'm not sure if I'm using it wrong and if it's related to the exception I'm getting on the contact picker close, but if you look at my other post you can see how I use it.

Sep 3, 2012 at 10:00 PM

I've added a comment on your previous post. I've only had a brief look at the file/contact pickers and need to investigate more in the future (although it will be at least a couple of weeks before I get chance).

Let me know if the improvements to the DataListSource I have suggested solve any of the problems you are experiencing here.

Andy