Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 点击建议自动完成对话框导航_C#_Xaml_Windows Phone 8 - Fatal编程技术网

C# 点击建议自动完成对话框导航

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>

我尝试在我的自动完成框中的建议点击上进行导航,但它与InvokeCommandAction不兼容,我尝试在命令中导航,以下是我的代码:

<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,但不会触发。它对您有效吗答案?