[英]XAML: Property not found in type
我正在尝试使用一些其他属性来构建自定义控件:
public class EntryWithBorder : Entry
{
public static readonly BindableProperty IsCurvedCornersEnabledProperty =
BindableProperty.Create(
"IsCurvedCornersEnabled",
typeof(bool),
typeof(EntryWithBorder),
true);
public bool IsCurvedCornersEnabled
{
get { return (bool)GetValue(IsCurvedCornersEnabledProperty); }
set { SetValue(IsCurvedCornersEnabledProperty, value); }
}
}
然后,我想在页面中使用自定义控件:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App.CustomControls;assembly=App"
x:Class="App.View.LoginPage"
BackgroundColor="{StaticResource BackgroundColor}">
<ScrollView>
<Grid RowSpacing="0" ColumnSpacing="25">
<Grid.RowDefinitions>
<RowDefinition Height="AUTO"/>
<RowDefinition Height="AUTO"/>
<RowDefinition Height="AUTO"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<BoxView BackgroundColor="White" Grid.Row="0" HeightRequest="50"/>
<!--header spacing-->
<BoxView BackgroundColor="White" Grid.Row="1"/>
<Image Source="test.PNG" Aspect="AspectFit" HorizontalOptions="CenterAndExpand"/>
<!-- <Image Source="CurvedLimiter.png" VerticalOptions="End" HeightRequest="50" Aspect="Fill"/>-->
<!--header-->
<BoxView BackgroundColor="White" Grid.Row="2" HeightRequest="100"/>
<StackLayout Grid.Row="1">
<local:EntryWithBorder IsCurvedCornersEnabled="True" Placeholder="Email" Text="super@super.de" x:Name="emailEntry" Style="{StaticResource LoginEntry}"/>
<Entry IsPassword="True" Placeholder="Password" Text="super" x:Name="passwordEntry" Style="{StaticResource LoginEntry}"/>
<Switch x:Name="autoLogin" IsToggled="True" HorizontalOptions="Center"/>
<Button Text="Login" x:Name="btnLogin" Clicked="btnLogin_Clicked" Style="{StaticResource LoginButton}"/>
</StackLayout>
<!--login-->
<BoxView BackgroundColor="White" Grid.Row="3"/>
</Grid>
</ScrollView>
</ContentPage>
找到了自定义控件“ local:EntryWithBorder”,但是找不到可绑定的属性“ IsCurvedCornersEnabled”。 相反,我收到错误XLS0413,在“ EntryWithBorder”类型内找不到该属性。
有任何想法吗?
提前致谢!
编辑2018-09-16:可以通过重新启动VS解决此问题。 但是,我必须为添加到代码中的每个新BindableProperty重新启动VS。
同样,我也遇到了一个新错误:将以下属性添加到代码中后,在初始化应用程序窗体时会出现异常:
public static readonly BindableProperty Corner123RadiussProperty =
BindableProperty.Create(
nameof(Corner123Radiuss),
typeof(double),
typeof(EntryWithBorder),
7);
// Gets or sets CornerRadius value
public double Corner123Radiuss
{
get { return (double)GetValue(Corner123RadiussProperty); }
set { SetValue(Corner123RadiussProperty, value); }
}
奇怪的是,我现在甚至没有从我的XAML代码中引用此属性。 在LoginPage中的InitializeComponents()方法中引发异常:
System.TypeInitializationException: The type initializer for 'App.CustomControls.EntryWithBorder' threw an exception.
我目前没有任何更多信息。
我将项目包装在以下文件中: VS Project
改变这个
public static readonly BindableProperty Corner123RadiussProperty =
BindableProperty.Create(
nameof(Corner123Radiuss),
typeof(double),
typeof(EntryWithBorder),
7);
至
public static readonly BindableProperty Corner123RadiussProperty =
BindableProperty.Create(
nameof(Corner123Radiuss),
typeof(double),
typeof(EntryWithBorder),
7.0);
此可绑定属性是double
精度类型,将默认值设置为7
将作为整数处理,因此需要为7.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.