This is a weird one, which doesn't reproduce consistently.
I have a Repeater/Scroller displaying data from a Choice. This data is loaded into memory before the page is displayed, so all should be fine there. As part of the data-load operation I set the .DefaultIndex property of the Choice to a value (depending on various flags in the data). If for some reason, at the end of the load operation this value is null or -1 it's set to 0.
Then in my MCML I have code like this (the very basics really);
<
Default Target="[ScrollingHandler.ScrollingData]" Value="[ScrollingData]"/>
<Default Target="[ScrollingData.Repeater]" Value="[ImgRepeater]"/>
<Binding Source="[Choice.Options]" Target="[ImgRepeater.Source]"/>
and this (which is invoked a quarter of a second after the page is displayed);
<
Changed Source="[SelIdx.Tick]">
<!--<Conditions>
<Equality Source="[Choice.DefaultIndex]" ConditionOp="GreaterThan" Value="0" />
</Conditions>-->
<Actions>
<Invoke Target="[ScrollingData.Scroll]" amount="[Choice.DefaultIndex]"/>
</Actions>
</Changed>
At times this works wonders, and the scroller is automatically moved to the "correct" item upon load, at other times it stays put on the first item in the list (this is due to the Timer.Interval I have found - if I make it larger, it takes longer to display the page, but the correct item is always selected) and again at other times it will throw a hissyfit and come up with an InvalidOperationException.
The entire errormessage is;
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Nullable object must have a value.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at Microsoft.MediaCenter.UI.ScrollingData.FocusBasedScrollingStrategy.Scroll(Int32 amount)
at Microsoft.MediaCenter.UI.ScrollingData.Scroll(Int32 amount)
so my initial thought was that for some reason Choice.DefaultIndex was not set properly, although stepping through the code (too many times to count - to be able to catch this exception in the first place) the value is ALWAYS correct as based on the data itself.
Then I found it would throw an exception if it tried ScrollingData.Scroll(0) hence I added the Condition in the rule above. This resolved the issue when DefaultIndex was 0, but it still happens from time to time where the value is between 0 and the maximum number of entries in Choice.Options.
I've just pulled out the last few strands of hair and would appreciate any input you may have on this. Even if it involves opening my window and throwing the computer out :D