BINDING DOES NOT RECOGNIZE TYPE

Giorgio Sfiligoi 391 Reputation points
2024-10-18T21:09:35.5033333+00:00

I have a custom component that exposes a property 'Amount64' of type Int64; I would like to bind it to a property 'Amount', also of type Int64, in the host page:

<components:MyNumericKeyboard x:Name="keypad" Amount64="{Binding Amount, Mode=OneWayToSource}"/>

Although the two properties are the same type, the compiler shows the following error:

Error (active)	XFC0009	No property, BindableProperty, or event found for "Amount64", or mismatching type between value and property.

I think the last part of the message: 'mismatching type' is my case.

How can I set the binding?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,084 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 81,191 Reputation points Microsoft External Staff
    2024-11-01T03:22:43.17+00:00

    Hello,

    Please change the Int64 to long for your property.

    public static readonly BindableProperty Amount64Property = BindableProperty.Create(
         propertyName: nameof(Amount64),
         returnType: typeof(long),
         declaringType: typeof(NewContent1),
         defaultValue: default(long)
    );
     
     
    public long Amount64
    {
         get => (long)GetValue(Amount64Property);
         set => SetValue(Amount64Property, value);
    }
    

    If you want to convert long to Int64, you can set convert it directly like following code. In C#, long and Int64 are the same. Long is a C# keyword, and Int64 is a structure in the .NET System namespace, both of which represent 64-bit signed integer types.

    long myLong = 123456789L;
    Int64 myInt64 = myLong; 
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Louis Sherwood 0 Reputation points
    2025-04-28T10:31:19.01+00:00

    I thought I was getting the same problem as Giorgio, I had a bool property in a custom control declared like this:

    public BindableProperty IsCheckedProperty;
    public bool IsChecked
    {
        get => (bool)GetValue(IsCheckedProperty);
        set => SetValue(IsCheckedProperty, value);
    }
    

    Then instantiated in the constructor:

    IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool?), typeof(CheckmarkButton));
    
    

    I could use this property in XAML as long as I was setting it with a static value like this:

    IsChecked="true"
    

    As soon as I tried to set it with a binding it would generate the error above. The fix is to declare the BindableProperty correctly as a static readonly property, instantiating it on the same line:

    public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckmarkButton));
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.