In my xamarin project I have a custom button controller:
[XamlCompilation(XamlCompilationOptions.Compile)]
public class AddToCartButton : Button
{
public static readonly BindableProperty SkuPoperty = BindableProperty.Create(nameof(Sku), typeof(ApiModels.SkuDetailModel), typeof(AddToCartButton));
public ApiModels.SkuDetailModel Sku
{
get { return (ApiModels.SkuDetailModel)GetValue(SkuPoperty); }
set { SetValue(SkuPoperty, value); }
}
public AddToCartButton()
{
this.Clicked += AddToCartButton_Clicked;
}
public AddToCartButton(ApiModels.SkuDetailModel sku)
{
this.Sku = sku;
this.Clicked += AddToCartButton_Clicked;
}
private async void AddToCartButton_Clicked(object sender, EventArgs e)
{
var response = await Helpers.ApiHelper.CurrentAccess.AddToCart(new List<ApiModels.CartItem>() {
new ApiModels.CartItem() {
ItemCode = Sku.ItemCode,
Quantity = 1
}
});
// handle add modal
}
}
This is the exact same way I've created BindableProperties for ContentViews and what have you.
In my xaml referencing this controller, I have:
<local:AddToCartButton Text="Add to Cart" Style="{ DynamicResource SkuAddToCart }" Sku="{Binding Sku}" />
This line is causing my builds to fail, with the error:
Severity Code Description Project File Line Suppression State
Error Position 44:44. No property, bindable property, or event found for 'Sku', or mismatching type between value and property....
I can't seem to figure out why I'm getting it. All my types are consistent. The object I'm trying to bind is done like this: public partial class SkuView : ContentView { public ApiModels.SkuDetailModel Sku { get; set; }
public SkuView(ApiModels.SkuDetailModel sku, string baseUrl, ApiModels.SimpleUser user)
{
BindingContext = this;
Sku = sku;
InitializeComponent();
Per request for xaml headers, here is the entire xaml file.
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:myApp.Controls"
x:Class="myApp.Views.Products.SkuView">
<ContentView.Content>
<StackLayout>
<Grid Style="{ DynamicResource SkuGrid }">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<StackLayout x:Name="ImageCell" Grid.Row="0" Grid.Column="0"></StackLayout>
<StackLayout x:Name="ContentCell" Grid.Row="0" Grid.Column="1">
<Label x:Name="DescriptionLabel" Style="{ DynamicResource SkuDescLabel }" />
<Label x:Name="ItemCodeLabel" Style="{ DynamicResource SkuItemCode }" />
<StackLayout x:Name="PricingLayout">
<!--<StackLayout Orientation="Horizontal">
<Label x:Name="PriceLabel" Style="{ DynamicResource SkuPricing }" />
<Label x:Name="PurchaseMultipleLabel" Style="{ DynamicResource SkuUom }" />
</StackLayout>-->
</StackLayout>
</StackLayout>
<StackLayout Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Button Text=" - " Style="{ DynamicResource SkuQtyStepper }" />
<Grid Margin="-10, 0">
<BoxView Color="DarkGray" Opacity=".6" Margin="0, 5"/>
<BoxView Color="White" Margin="2, 7"/>
<local:BorderlessEntry Style="{ DynamicResource SkuQtyEntry }" Keyboard="Numeric" Margin="2" HorizontalTextAlignment="Center" />
</Grid>
<Button Text=" + " Style="{ DynamicResource SkuQtyStepper }" />
</StackLayout>
<!--<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Button Text=" - " Style="{ DynamicResource SkuQtyStepper }" />
<local:BorderedEntry Style="{ DynamicResource SkuQtyEntry }" Keyboard="Numeric" HeightRequest="20" />
<Button Text=" + " Style="{ DynamicResource SkuQtyStepper }" />
</StackLayout>-->
<local:AddToCartButton Text="Add to Cart" Style="{ DynamicResource SkuAddToCart }" Sku="{Binding Sku}" />
<!--<Button Text="Add to Cart" Style="{ DynamicResource SkuAddToCart }" />-->
</StackLayout>
</Grid>
<Grid HeightRequest="1" Style="{ DynamicResource BackgroundMediumGray }" />
</StackLayout>
</ContentView.Content>
In the property name, you have a typo:
public static readonly BindableProperty SkuPoperty = BindableProperty.Create(nameof(Sku), typeof(ApiModels.SkuDetailModel), typeof(AddToCartButton));
SkuPoperty => SkuProperty
Edit: To elaborate, Xamarin requires to have PropertyNameProperty naming convention: Creating a bindable property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With