为什么 FlipView 忽略 SelectedItem [英] Why does FlipView ignore SelectedItem

查看:26
本文介绍了为什么 FlipView 忽略 SelectedItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 FlipView 来显示一些项目并开始显示特定项目.

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.

现在是 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.

这是故意的吗?还是bug?

Is this intentional?, or is it a bug?

推荐答案

试试这个

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

  • 您的 SelectedItem 需要是一个 TwoWay 绑定才能工作,因为该值是由控件和视图模型设置的.
  • 这篇关于为什么 FlipView 忽略 SelectedItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆