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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题