我有一个listpicker,其中我使用了交互触发来触发选择更改事件。但是它显示了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;
}
}
答案 0 :(得分:1)
在您的InvokeCommandAction更新CommandParameter中,如下所示:CommandParameter="{Binding ElementName=listPickerAccount, Path=SelectedItem}"
试试并告诉我。
答案 1 :(得分:0)
试试这个:
// 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
}