Share via

code snippet for BindableProperty

Eduardo Gomez 4,316 Reputation points
2023-12-06T17:09:40.53+00:00

I am creating a BindableProperty snippet, so far, I have this.

CodeSnippet Format="1.0.0">
		<Header>
			<Title>BindableProperty</Title>
			<Shortcut>bp</Shortcut>
			<Description>This will create a BindableProperty for a custom control in .net Maui</Description>
			<Author>Eduardo Gomez</Author>
		</Header>
		<Snippet>
			<Code Language="CSharp">
				<![CDATA[
					public static readonly BindableProperty $Text$Property = BindableProperty.Create(
						nameof($PropertyName$), typeof($PropertyType$), typeof($ControlName$), default($PredefinedValue$));
						
					public TypeOfPrperty PropertyName {

					get => (TypeOfPrperty)GetValue(BindiablePropertyName);
					set => SetValue(BindiablePropertyName, value);
					}
					
                ]]>
			</Code>
			<Declarations>
				<Literal>
					<ID>BindiablePropertyName</ID>
					<Default>BindiablePropertyName</Default>
					<ToolTip>The name of the bindiable property</ToolTip>					
					<ID>PropertyName</ID>
					<Default>PropertyName</Default>
					<ToolTip>The name of the property</ToolTip>
					<ID>TypeOfPrperty</ID>
					<Default>string</Default>
					<ToolTip>The type of the of the property</ToolTip>
					<ID>CustomControlName</ID>
					<Default>customCntrol</Default>
					<ToolTip>The name of the custom control</ToolTip>
					<ID>DefaultValue</ID>
					<ToolTip>The predefined value of the control</ToolTip>
				</Literal>
			</Declarations>
		</Snippet>
	</CodeSnippe
Developer technologies | .NET | .NET Multi-platform App UI
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.


1 answer

Sort by: Most helpful
  1. Eduardo Gomez 4,316 Reputation points
    2023-12-11T15:00:44.2566667+00:00

    I fixed the problem. for people who want a shortcut for reating bindable properties or custom controls, here you go

    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    	<CodeSnippet Format="1.0.0">
        <Header>
            <Title>BindableProperty</Title>
            <Shortcut>bp</Shortcut>
            <Description>This will create a BindableProperty for a custom control in .NET MAUI</Description>
            <Author>Eduardo Gomez</Author>
        </Header>
        <Snippet>
            <Code Language="CSharp">
                <![CDATA[
                public static readonly BindableProperty $PropertyName$Property = BindableProperty.Create(
                    nameof($PropertyName$), typeof($TypeOfProperty$), typeof($CustomControlName$));
    
                public $TypeOfProperty$ $PropertyName$
                {
                    get => ($TypeOfProperty$)GetValue($PropertyName$Property);
                    set => SetValue($PropertyName$Property, value);
                }
                ]]>
            </Code>
            <Declarations>
                <Literal>
                    <ID>PropertyName</ID>
                    <Default>MyProperty</Default>
                    <ToolTip>The name of the property</ToolTip>
                </Literal>
                <Literal>
                    <ID>TypeOfProperty</ID>
                    <Default>string</Default>
                    <ToolTip>The type of the property</ToolTip>
                </Literal>
                <Literal>
                    <ID>CustomControlName</ID>
                    <Default>CustomControl</Default>
                    <ToolTip>The name of the custom control</ToolTip>
                </Literal>
                <Literal>
                    <ID>DefaultValue</ID>
                    <Default>"Default value"</Default>
                    <ToolTip>The predefined value of the property</ToolTip>
                </Literal>
            </Declarations>
        </Snippet>
      </CodeSnippet>
    </CodeSnippets>
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

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