sweekly 2013-05-10 02:36 采纳率: 0%
浏览 2040

windows phone mvvm开发中关于listpicker问题

在没使用mvvm开发时,对于listpicker 木有发现啥问题

当在mvvm中 listpicker 的SelectionChanged事件,会出现第一次选择某一项时,不管选择哪一项,都会获取到 索引为0的 第一项,第二次选择时,则获取到 第一次选择的那一项,之后以此类推。困惑啊

如果是 直接在cs 文件写该事件的话 在加载的时候 就会运行到 SelectionChanged事件,并获取到默认第一项的值

请教下大家 有没有遇到此类问题

                   再次感谢

贴上代码

<phone:PhoneApplicationPage.Resources>
        <Models:CommonConverters x:Key="CommonConverters"/>
        <DataTemplate x:Key="ListPickerFullTemplate">
            <TextBlock Text="{Binding Description}" Margin="0,0,0,12"  TextWrapping="Wrap"/>
        </DataTemplate>
        <DataTemplate x:Key="ListPickerItemTemplate">
            <TextBlock Margin="0,0,0,0" HorizontalAlignment="Center" Text="{Binding Description}"/>
        </DataTemplate>
     </phone:PhoneApplicationPage.Resources>
 <toolkit:ListPicker  x:Name="_1StepListPicker"  Grid.Row="0"   ItemsSource="{Binding Products}" FullModeItemTemplate="{StaticResource ListPickerFullTemplate}" ItemTemplate="{StaticResource ListPickerItemTemplate}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <Command:EventToCommand Command="{Binding SelectedProductCommand}" CommandParameter="{Binding SelectedItem,ElementName=_1StepListPicker}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </toolkit:ListPicker>
--------------------------------------------------------------
 SelectedProductCommand = new RelayCommand<Product>((p) =>
            {
                if (Products.CurrentItem != null)
                {
                    //获取当前选中列
                    Product selectedProduct = (Product)p;// Products.CurrentItem;
                }
            }
            ); 



public ObservableCollection<Product> Items
        {
            get;
            private set;
        }

        public RelayCommand<Product> SelectedProductCommand
        {
            get;
            private set;
        }
 private ICollectionView CreateView(IEnumerable source)
        {
            CollectionViewSource cvs = new CollectionViewSource();
            cvs.Source = source;
            return cvs.View;
        }
        private ICollectionView products;
        public ICollectionView Products
        {
            get
            {
                if (this.products == null)
                {
                    this.products = CreateView(this.Items);
                }
                return this.products;
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private ObservableCollection<Name> _listOfnames;
        public ObservableCollection<Name> ListOfNames
        {
            get { return _listOfnames; }
            set
            {
                _listOfnames = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("ListOfNames"));
            }
        }
  • 写回答

1条回答 默认 最新

  • franzhong 2013-05-14 16:07
    关注

    估计多数是你事件方法使用有误
    可上代码让大家分析一下原因

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog