'System.Windows.Markup.XamlParseException'无法分配给属性'Microsoft.Phone.Controls.PhoneTextBox.ActionIconTapped'

时间:2014-07-23 20:00:41

标签: c# windows-phone-8

我在Windows Phone上获得了System.Windows.Markup.XamlParseException。附加信息说:

  

无法分配给属性'Microsoft.Phone.Controls.PhoneTextBox.ActionIconTapped'。

以下是它引用的PhoneTextBox

<toolkit:PhoneTextBox
   Grid.Row="1"
   x:Name="nameInput"
   VerticalAlignment="Top"
   InputScope="Text"
   Hint="Enter your first name"
   ActionIcon="/Assets/next.png"
   ActionIconTapped="nameInput_ActionIconTapped"
/>

和事件处理程序:

void nameInput_ActionIconTapped(object sender, RoutedEventArgs e)
{
   this.NavigationService.Navigate(GreetingPage.BuildNavigationUri(nameInput.Text));
}

这是GreetingPage的方法:

public static Uri BuildNavigationUri(string name)
{
   return new Uri("/GreetingPage.xaml?name=" + name, UriKind.Relative);
}

你能帮忙解决这个异常并找出它不想分配的原因吗?

1 个答案:

答案 0 :(得分:0)

加入System.Windows.Interactivity

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

然后添加以下内容:

<toolkit:PhoneTextBox ActionIcon="/Assets/feature.search.png">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="ActionIconTapped">
            <i:InvokeCommandAction Command="{Binding SomeCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</toolkit:PhoneTextBox>

从以下链接中获取答案:

http://forums.xamarin.com/discussion/14299/how-to-map-the-actionicontapped-event-handler-of-phonetextbox-using-mvvmcross