ObservableCollection update related to Pivot errors for SelectedIndex> = 2 (wp7)

I have an observable set associated with a rotary control in my user interface. When I try to update the collection elements (clear () and recreate), everything will work fine if only the selected rotation control value is greater than or equal to 2.

In this case, I get an ArgumentOutOfRange exception when I try to call Add () on the observable collection. It is very strange.

I tried creating a new observable collection, and then the Add () elements there seem to work, but I am not updating the user interface if I call the update function twice.

What could be wrong? This is mistake?

+3
source share
5 answers

This is a known issue.

Unhandled exception while setting up the Pivot Control SelectedItem / SelectedIndex element for the third PivotTable element (WP7)

Disabling navigation / (binding?) To the loaded event is a workaround.

+1
source

You probably solved it, but here is what I did. As mentioned earlier, this is a known “bug” / limitation. However, you can set SelectedIndex in the Loaded event for the page.

See here: http://christian-helle.blogspot.com/2011/02/working-around-pivot-selectedindex.html

It helped me, and now everything works fine =)

+1
source

, . , . SelectedItem , .

, , , .

0

. Pivot , . , , , , Panorama Control, PanoramaItems.

0

@Jimmy Engtröm. , , .

<controls:Pivot x:Name="pivotCtrl" Title="{Binding ApplicationTitle}" 
Loaded="OnPivotControlLoaded" Opacity="1">

:

private void OnPivotControlLoaded(object sender, RoutedEventArgs e)
{
    // Restore the Pivot control SelectedIndex
    if (State.ContainsKey(SelectedPivotIndexKey))
    {
        pivotCtrl.SelectedIndex = State.Get<int>(SelectedPivotIndexKey);
    }

    myStoryboard.Begin();
}

, ? , Load, . , ... , . Visibility, . , Opacity 1 XAML. :

<Storyboard x:Name="myStoryboard">
    <DoubleAnimation
        Storyboard.TargetName="pivotCtrl"
        Storyboard.TargetProperty="Opacity"
        From="0.0" To="1.0" Duration="0:0:01"
        />
</Storyboard>

( , , MyApp.Helpers, System.Collections.Generic)

public static T Get<T>(this IDictionary<string, object> dictionary, string key)
{
    return (T)dictionary[key];
}

public static void AddOrReplace<T>(this IDictionary<string, T> dictionary, string key, T item)
{
    if (dictionary.ContainsKey(key))
        dictionary.Remove(key);

    dictionary.Add(key, item);
}

Again, this is not the biggest fix, but it works well, and attenuation is something that I can use elsewhere.

0
source

Source: https://habr.com/ru/post/1781233/


All Articles