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". Instead I get an error XLS0413 the property could not be found within type "EntryWithBorder".
Any ideas?
Thanks in advance!
Edit 2018-09-16: This problem could be solved by restarting VS. However I have to restart VS for every new BindableProperty that I add to the code.
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. The Exception is thrown in the LoginPage within the InitializeComponents() method:
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.