C# 点击建议自动完成对话框导航
我尝试在我的自动完成框中的建议点击上进行导航,但它与InvokeCommandAction不兼容,我尝试在命令中导航,以下是我的代码:C# 点击建议自动完成对话框导航,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我尝试在我的自动完成框中的建议点击上进行导航,但它与InvokeCommandAction不兼容,我尝试在命令中导航,以下是我的代码: <toolkit:AutoCompleteBox ItemsSource="{Binding A}" ValueMemberBinding="{Binding B}" Style="{StaticResource SearchStyle}"> <toolkit:AutoCompleteBox.ItemTemplate>
<toolkit:AutoCompleteBox ItemsSource="{Binding A}" ValueMemberBinding="{Binding B}" Style="{StaticResource SearchStyle}">
<toolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding Test, Mode=OneWay, Source={StaticResource Main}}" CommandParameter="{Binding Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<TextBlock Text="{Binding B}"/>
</StackPanel>
</DataTemplate>
</toolkit:AutoCompleteBox.ItemTemplate>
</toolkit:AutoCompleteBox>
尝试以下方法:
<toolkit:AutoCompleteBox Name="XPTO">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<i:InvokeCommandAction Command="{Binding Test, Mode=OneTime}" CommandParameter="{Binding ElementName=XPTO, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</toolkit:AutoCompleteBox>
您可以将自动完成框SelectedItem作为参数发送。在ViewModel中,您只需要
public RelayCommand<TYPEOFSELECTEDITEM> Test{ get; private set; }
public RelayCommand Test{get;private set;}
在ViewModel的构造函数中,类似于:
this.Test= new RelayCommand<TYPEOFSELECTEDITEM>(()=>MessageBox.Show("Hello world"));
this.Test=newrelaycommand(()=>MessageBox.Show(“helloworld”);
如果您没有使用ViewModel,那么这将转到设置DataContext的位置。
如果您使用的是ViewModel,则不应调用MessageBox.Show,但这是另一回事
注意,显示命令的测试代码!如果进行调试,则会触发测试命令?在该命令中,我仅显示测试的MessageBox,但不会触发。它对您有效吗答案?