【发布时间】: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