创建新命名空间时获取System.Reflection.TargetInvocationException

时间:2016-06-12 14:13:32

标签: c# xaml xamarin

我尝试定义用于创建条目行为的新命名空间,如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TK.CustomMap.Sample.TKLoginPage"
             xmlns:local="clr-namespace:TK.CustomMap.Sample.Behaviors;assembly=TK.CustomMap.Sample">
  <StackLayout Spacing="15" Padding="10,20,10,20">
    <Label Text="Welcome to Trackware" FontSize="25" TextColor="Blue" HorizontalOptions="CenterAndExpand"></Label>
    <Label Text="Your easy way to track" FontSize="15" HorizontalOptions="CenterAndExpand"></Label>

    <Entry HorizontalOptions="FillAndExpand" Placeholder="Email/Mobile Number" FontSize="15" x:Name="user_name" TextChanged="enable_login_btn">
      <Entry.Behaviors>
        <local:IsValidValidator x:Name="userNameValidator"/>
      </Entry.Behaviors>
    </Entry>

    <Entry HorizontalOptions="FillAndExpand" Placeholder="PIN/Password" IsPassword="True" FontSize="15" x:Name="password" TextChanged="enable_login_btn">
      <Entry.Behaviors>
        <local:IsValidValidator x:Name="passwordValidator"/>
      </Entry.Behaviors>
    </Entry>

    <Button HorizontalOptions="Center" Text="Login" BackgroundColor="Blue" TextColor="White" IsEnabled="False" x:Name="login_btn" Clicked="login_user"></Button>
  </StackLayout>
</ContentPage>

但是当我尝试运行它时,我有以下例外:

  

System.Reflection.TargetInvocationException:抛出了异常   通过调用的目标。

OnOtherHand,当我删除命名空间声明并使用项目正确运行时。

这是我的验证码:

using Xamarin.Forms;

namespace TK.CustomMap.Sample.Behaviors
{
    class IsValidValidator : Behavior<Entry>
    {
        protected override void OnAttachedTo(Entry bindable)
        {
            bindable.Text = "test";
        }

        protected override void OnDetachingFrom(Entry bindable)
        {

        }
    }
}

有什么想法吗?

0 个答案:

没有答案