繁体   English   中英

如何在wp8中使用mvvm模式在listpicker中实现选择更改事件?

[英]how to implement selection changed event in listpicker using mvvm pattern in wp8?

我有一个列表选择器,其中我使用了交互触发器来触发选择更改事件。但是它显示了Xaml解析异常错误。

xaml页面中的代码是:

<toolkit:ListPicker x:Name="listPickerAccount" ItemsSource="{Binding AccountTypeList,Mode=TwoWay}">                               
     <i:Interaction.Triggers>
          <i:EventTrigger EventName="SelectionChanged" >
              <i:InvokeCommandAction  Command="{Binding AccountTypeSelectionCommand}"
                   CommandParameter="{Binding ElementName=listPickerAccount}"> 

              </i:InvokeCommandAction>
          </i:EventTrigger>
     </i:Interaction.Triggers>

</toolkit:ListPicker>

我在viewmodel中将属性设置为

public ICommand AccountTypeSelectionCommand
{
   get
   {
     return new RelayCommand<object>((x) =>
     {
          string item = (string)(x as ListPicker).SelectedItem;
          ListPickerSelection(item);
     });
   }
}

private void ListPickerSelection(string item)
{
  if (AccountType != null)
  {
      AccountType = item;
      return;
  }
}

在您的InvokeCommandAction中更新如下的CommandParameter: CommandParameter="{Binding ElementName=listPickerAccount, Path=SelectedItem}"

试试这个,告诉我。

尝试这个 :

// XAML中

<i:Interaction.Triggers>
                    <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged" >
                    <command:EventToCommand  Command="{Binding TestCommand}" PassEventArgsToCommand="">
                    </command:EventToCommand>
                </i:EventTrigger>
            </i:Interaction.Triggers>
    </toolkit:ListPicker>

//视图模型

public RelayCommand TestCommand{ get; set; } 

TestCommand= new RelayCommand( TestMethode);  

    private void TestMethode( SelectionChangedEventArgs args )  
    {  
        //TODO   args.AddItems can be help 
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM