[英]XAML: Property not found in type
I am trying to build a custom Control with some additional properties: 我正在尝试使用一些其他属性来构建自定义控件:
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); }
}
}
Then I want to use the custom control from within a page: 然后,我想在页面中使用自定义控件:
<?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>
The custom control "local:EntryWithBorder" is found, however it cant find the bindableproperty "IsCurvedCornersEnabled". 找到了自定义控件“ local:EntryWithBorder”,但是找不到可绑定的属性“ IsCurvedCornersEnabled”。 Instead I get an error XLS0413 the property could not be found within type "EntryWithBorder".
相反,我收到错误XLS0413,在“ EntryWithBorder”类型内找不到该属性。
Any ideas? 有任何想法吗?
Thanks in advance! 提前致谢!
Edit 2018-09-16: This problem could be solved by restarting VS. 编辑2018-09-16:可以通过重新启动VS解决此问题。 However I have to restart VS for every new BindableProperty that I add to the code.
但是,我必须为添加到代码中的每个新BindableProperty重新启动VS。
So also, I got a new bug: As soon as I add the following Property to the code, I get an exception when the App Forms get initialized: 同样,我也遇到了一个新错误:将以下属性添加到代码中后,在初始化应用程序窗体时会出现异常:
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); }
}
The strange thing is that I dont even reference this property from my XAML code at this point. 奇怪的是,我现在甚至没有从我的XAML代码中引用此属性。 The Exception is thrown in the LoginPage within the InitializeComponents() method:
在LoginPage中的InitializeComponents()方法中引发异常:
System.TypeInitializationException: The type initializer for 'App.CustomControls.EntryWithBorder' threw an exception.
I don't get any more information at this point. 我目前没有任何更多信息。
I wrapped the project in a file here: VS Project 我将项目包装在以下文件中: VS Project
Change this 改变这个
public static readonly BindableProperty Corner123RadiussProperty =
BindableProperty.Create(
nameof(Corner123Radiuss),
typeof(double),
typeof(EntryWithBorder),
7);
To 至
public static readonly BindableProperty Corner123RadiussProperty =
BindableProperty.Create(
nameof(Corner123Radiuss),
typeof(double),
typeof(EntryWithBorder),
7.0);
This bindable property is double
type, setting default value with 7
is handled as integer so it needs to be 7.0
此可绑定属性是
double
精度类型,将默认值设置为7
将作为整数处理,因此需要为7.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.