DataBinding Error No Property, Bindable Property or Event Found

Hey Guys,

i want to make a Bindable Property but i get this Error:
No Property, Bindable Property or Event Found

in Xaml:
Checked="{Binding NoticeUserData}"

in my class:
public static BindableProperty CheckboxProperty =
BindableProperty.Create(nameof(Checked), typeof(bool), typeof(Checkbox), true);

public bool Checked
{
get
{
return (bool)GetValue(CheckboxProperty);
}
set
{
SetValue(CheckboxProperty, value);
}
}

What do i miss? Can anyone help me i have never done before a databinding Property.

Thanks for help!

Posts

  • anton.emelyancevanton.emelyancev USMember ✭✭

    Try this. Pay attention for lines about BindableProperty naming rules.
    There are lot of usefull stuf in xamarin documentation.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    1 - Here's a link to an article on reusable controls that should help with the bindable property issue
    https://redpillxamarin.com/2017/01/28/206-reusable-controls/

    2 - Here a link to an article on formatting your post so the code doesn't get mangled by the forum parser.
    https://redpillxamarin.com/2016/12/13/faq-frequently-asked-questions/

  • BenjaminTooleBenjaminToole USMember ✭✭

    The Placeholder for the BindableProperty 'CheckboxProperty' should always match the name without 'Property'.

    So instead of 'Checked' it should be 'Checkbox'.

    Its a naming convention that Xamarin goes by. Took me a while to figure out too as it wasn't well documented.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Snippets are a wonderful feature of Visual Studio.
    Long along I added a snippet for making BindableProperties. now I just type nubnd {tab} then fill in variable fields.
    Add this as a .snippet file to your Visual Studio C# snippets directory and make life a lot easier on yourself.

    <?xml version= "1.0" encoding= "utf-8" ?>
    <CodeSnippets  xmlns= "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet ">
      <CodeSnippet Format= "1.0.0 ">
        <Header>
          <Title> New BindableProperty</Title>
          <Shortcut> nubnd</Shortcut>
          <Description> Code snippet for a BindableProperty </Description>
          <Author> Clint StLaurent</Author>
          <SnippetTypes>
            <SnippetType> Expansion</SnippetType>
          </SnippetTypes>
        </Header>
        <Snippet>
          <Declarations>
            <Literal>
              <ID> type</ID>
              <ToolTip> BindableProperty type</ToolTip>
              <Default> string</Default>
            </Literal>
            <Literal>
              <ID> property</ID>
              <ToolTip> Property name</ToolTip>
              <Default> MyProperty</Default>
            </Literal>
            <Literal>
              <ID> parentType</ID>
              <ToolTip> Type of the parent control</ToolTip>
              <Default> ParentControlType</Default>
            </Literal>
            <Literal>
              <ID> defaultValue</ID>
              <ToolTip> defaultValue</ToolTip>
              <Default> string.Empty</Default>
            </Literal>
    
          </Declarations>
          <Code Language= "csharp ">
            <![CDATA[
            #region $property$ (Bindable $type$)
            public static readonly BindableProperty $property$Property = 
                BindableProperty.Create(propertyName: "$property$",
                                        returnType: typeof($type$),
                                        declaringType: typeof($parentType$),
                                        defaultValue: $defaultValue$);
            public $type$ $property$
            {
                get { return ($type$)GetValue($property$Property); }
                set { SetValue($property$Property, value); }
            }
            #endregion $property$ (Bindable $type$)
    
            $end$]]>
          
        
      
    
    
  • Thanks for all Answers.

    Special Thanks to BenjaminToole that was the problem Thank you :)

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    @BenjaminToole said:
    The Placeholder for the BindableProperty 'CheckboxProperty' should always match the name without 'Property'.

    So instead of 'Checked' it should be 'Checkbox'.

    Its a naming convention that Xamarin goes by. Took me a while to figure out too as it wasn't well documented.

    Great answer. I would also point out that CheckBoxProperty is a bad name and does not follow industry naming conventions. IsChecked would be a property name for a bool of this purpose. Following naming conventions keeps the rest of your team from being confused by your code, and shows you care about following standards.
    https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/general-naming-conventions

Sign In or Register to comment.