Raymen
Raymen

Reputation: 592

Pivot control MVVM-Light-EventToCommand SelectedIndex sends previous index

I get the index of the Pivot item I'm leaving, not the Pivot Item that I am going to.
I have searched for some time now and can think of some solutions like using an event in the view and then sending a message using MVVM-Light to the ViewModel. But I'd rather not do that, I'd rather stick to this current implementation, slightly different of course.

Any help is appreciated

My xaml:

    <controls:Pivot x:Name="ContentPivot" Margin="12,0,12,0">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <cmd:EventToCommand Command ="{Binding SelectSlideCommand}"
                                        CommandParameter="{Binding SelectedIndex, ElementName=ContentPivot}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>

        <controls:PivotItem x:Name="PivotItem0" Header="0">
            <Image Source="{Binding ViewingSlides[0].Path}"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </controls:PivotItem>

        <controls:PivotItem x:Name="PivotItem1" Header="1">
            <Image Source="{Binding ViewingSlides[1].Path}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </controls:PivotItem>

        <controls:PivotItem x:Name="PivotItem2" Header="2">
            <Image Source="{Binding ViewingSlides[2].Path}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </controls:PivotItem>
    </controls:Pivot>

and c#:

    public RelayCommand<int> SelectSlideCommand;

    SelectSlideCommand = new RelayCommand<int>((pivotItem) => SelectSlideAction(pivotItem));

    void SelectSlideAction(int parameter)
    {
        currentIndex = parameter;

        UpdateViewingSlides();
        Debug.WriteLine("SelectSlideAction: " + parameter);
    }

Upvotes: 1

Views: 1741

Answers (1)

Ankesh
Ankesh

Reputation: 4885

Do you have `SelectedItem Property in your Control... you can hook it up in Your ViewModel to a property in a TwoWay binding Mode to always get the updated Value (Then you will not need this command).... Also yoou can try

        <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <cmd:EventToCommand Command ="{Binding SelectSlideCommand}"
                                    CommandParameter="{Binding SelectedItem, ElementName=ContentPivot}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

Upvotes: 2

Related Questions