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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料