Pivot ActivateItem ArgumentException

Dec 19, 2010 at 4:18 PM

Hi there.

I'm lost with a problem I'm having with the WP7 Pivot.

I have several pivot items and have set it up as directed in the 'Working with Windows Phone 7' wiki.

I have an initial screen that provides shortcuts to my pivot, so when clicking one of the shortcut buttons I want to go through to the view with pivots and activate the selected pivot item.

My code is as follows:

 

protected override void OnActivate()
{
    foreach (IScreen screen in Items)
    {
        if (screen.DisplayName == SelectedSection)
        {
            ChangeActiveItem(screen, false);
            //ActivateItem(screen);
            return;
        }
                
    }
}

This works the first time round, but if I click back and then select another shortcut I get the following UnhandledException:

 

{"The parameter is incorrect. "}
    [System.ArgumentException]: {"The parameter is incorrect. "}
    _data: null
    _HResult: -2147024809
    _innerException: null
    _message: "The parameter is incorrect. "
    _methodDescs: null
    _optionalData: null
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147024809
    InnerException: Could not evaluate expression
    Message: "The parameter is incorrect. "
    StackTrace: Could not evaluate expression


Can anyone shed any light on this and advise me how to resolve.

thanks in advance.

Kamran

 

Dec 19, 2010 at 6:21 PM

I would have probably used OnInitialize override to set up the initially active item, but it's unlikely that this will solve your problem.
Even though I cannot tell for sure, since there is no stack trace, it seems one of those strange messages related to binding issues. Did you apply the PivotFix? 
If you have a chance to put a simple repro together, it will definitely help to investigate the source of the problem. 

Dec 20, 2010 at 9:28 AM

Try apply the PivotFix as marcoamendola suggested.

And there is also a sample application that shows how to use Pivot in some real-world scenarios.

Dec 20, 2010 at 7:52 PM

Hi there,

to confirm, yes I am using the pivot fix.  I've attached a sample solution that exhibits the problem.

http://cid-87332ab1b54fd720.office.live.com/self.aspx/.Public/Caliburn.Micro.HelloWP7%5E_PivotTest.zip

I've also just discovered that the following line makes a difference:

container.RegisterSingleton(typeof(PageTwoViewModel), "PageTwoViewModel", typeof(PageTwoViewModel));  //NOTE: is this is PerRequest the error stops

If I register the viewmodel that has the pivot as PerRequest the error doesn't happen anymore, but is fairly consistent if singleton.  I'd prefer singleton for performance reasons as well as the jumping from item[0] to item[x] behaviour that happens every time.

thanks

Kamran

Dec 24, 2010 at 2:11 PM

realise it Christmas Eve, any thoughts on this though?

Coordinator
Dec 25, 2010 at 7:53 PM

The jumping item behavior may be unavoidable to do the problems with the Pivot control. I'm not sure, but it's going to take some experimentation for sure. Perhaps someone with more experience can comment on that. It seams like the problem you are having is related to the Pivot's databinding issues. If moving to a PerRequest solves the problem, I would do that. It may be that you can make the Screen itself PerRequest and a separate component that it uses Singleton to get around whatever performance issues you may enounter. As a last result, you can override the OnLoad of the screen an manually manipulate the Pivot rather than databind to it.