listPicker不更新选择全模式 [英] listPicker not updating selection in full mode

查看:123
本文介绍了listPicker不更新选择全模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有人知道,$更改选定项目时,扩展模式设置为唯一的全模式P $ pvents它listpicker的一个错误。它总是出于某种原因要追溯到选定的默认项。

does anyone know of a bug in listpicker that prevents it from changing selected items when expansion mode is set to full mode only. It always for some reason goes back to the default item that is selected.

推荐答案

我假设你有一些code在Page_Loaded其中填充和/或设置ListPicker的SelectedIndex。

I am assuming that you have some code in your Page_Loaded which populates and/or sets the SelectedIndex of the ListPicker.

您需要确保您只设置的值在进入页面。

You need to ensure that you only set the value on entering the page.

    private void PhoneApplicationPage_Loaded(object sender, EventArgs e)
    {


        DataContext = App.ViewModel.something;
        if (MyListPicker.SelectedIndex == -1)
        {
            MyListPicker.ItemsSource   = App.ViewModel.SomeList;
            MyListPicker.SelectedIndex = App.ViewModel.MyBinding;
        }
    }

您也可以确保你忽略的启动选择更改(装在一个页面绑定时,可以会多次),只有捕获用户发起的更改。

You may also ensure that you ignore the startup selection changes (which can fire several times when loading and binding in a page) and only catch user initiated changes.

    private void MyListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (e.RemovedItems != null && e.RemovedItems.Count > 0)
        {
            if (this.MyListPicker.SelectedItem != null)
            {              
                // Do something
            }
        }  
    }

这篇关于listPicker不更新选择全模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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