Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does FlipView ignore SelectedItem

I'd like to use a FlipView to display some items and start showing a specific item.

For this, I have defined a view model class:

class MyDataContext
{

    public MyDataContext()
    {
        Items = new List<MyClass>();
        Items.Add(new MyClass("1"));
        Items.Add(new MyClass("2"));
        Items.Add(new MyClass("3"));
        SelectedItem = Items[1];
    }

    public List<MyClass> Items { get; set; }
    public MyClass SelectedItem { get; set; }
}

As you can see, the selected item is not the first item.

Now for the XAML:

    <FlipView ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}"></FlipView>

However, when I run the app, the flip view shows the first item, not the second item.

Is this intentional?, or is it a bug?

like image 354
user380719 Avatar asked May 04 '12 01:05

user380719


1 Answers

Try this

<FlipView
    ItemsSource="{Binding Items}"
    SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
  • your SelectedItem needs to be a TwoWay binding for it to work, since the value is set by both the control and the view model.
like image 51
Filip Skakun Avatar answered Sep 26 '22 03:09

Filip Skakun