【问题标题】:Getting "Exception has been thrown by the target of an invocation." in custom control获取“调用的目标已引发异常。”在自定义控件中
【发布时间】:2017-04-30 03:54:15
【问题描述】:

我在 Xamarin 跨平台中创建了自定义条目控件。但不知道为什么异常来了。我哪里做错了?

这是我的代码

CustomEntry.cs

public class CustomEntry : Entry
    {
        public static readonly BindableProperty cornerRadiusProperty = BindableProperty.Create("Radius",typeof(double),typeof(CustomEntry),0);
        public double CornerRadius { 
            get { return (double)GetValue(cornerRadiusProperty);}
            set { SetValue(cornerRadiusProperty, value);  }
        }
    }

MyXaml 页面

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:cl="clr-namespace:customcontrolapp;assembly=customcontrolapp" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="customcontrolapp.MyXaml" >
    <ContentPage.Content>
        <cl:CustomEntry Text="Sample" />
    </ContentPage.Content>
</ContentPage>

【问题讨论】:

  • 这下面一定有一个异常。仔细检查您的输出窗口。
  • 您将 int 作为默认值,它无法处理为双精度值。尝试 0.0 作为默认值。此外,propertyName 参数设置为Radius,而您的属性称为CornerRadius。为此,它们应该匹配。你也可以使用nameof(CornerRadius) 来减少你的魔术字符串使用:)
  • @StevenThewissen 谢谢..你的建议奏效了!!

标签: xamarin xamarin.ios xamarin.forms


【解决方案1】:

我已解决此异常,将链接器选项链接全部更改为 SDK 链接。 谢谢

【讨论】:

    猜你喜欢
    • 2021-12-27
    • 2021-03-08
    • 1970-01-01
    • 2019-01-22
    • 2018-11-08
    • 2018-02-14
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    相关资源
    最近更新 更多