欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wpf 自定义控件依赖属性代码片段

程序员文章站 2022-03-04 11:51:14
...
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
	<CodeSnippet Format="1.0.0">
		<Header>
			<Title>dp</Title>
			<Shortcut>dp</Shortcut>
			<Description>DependencyProperty的代码片段</Description>
			<Author>wp</Author>
			<SnippetTypes>
				<SnippetType>Expansion</SnippetType>
			</SnippetTypes>
		</Header>
		<Snippet>
			<Declarations>
				<Literal Editable="false">
					<ID>classname</ID>
					<ToolTip>类名</ToolTip>
					<Function>ClassName()</Function>
					<Default>ClassNamePlaceholder</Default>
				</Literal>
				<Literal>
					<ID>type</ID>
					<ToolTip>属性类型</ToolTip>
					<Default>int</Default>
				</Literal>
				<Literal>
					<ID>property</ID>
					<ToolTip>属性名</ToolTip>
					<Default>MyProperty</Default>
				</Literal>
				<Literal>
					<ID>wpdp</ID>
					<ToolTip>依赖属性名</ToolTip>
					<Default>MyDependencyProperty</Default>
				</Literal>
			</Declarations>
			<Code Language="csharp"><![CDATA[ public $type$ $property$
        {
            get => ($type$)GetValue($wpdp$);
            set => SetValue($wpdp$, value);
        }

        public static readonly DependencyProperty $wpdp$
            = DependencyProperty.Register(nameof($property$), typeof($type$), typeof($classname$), new PropertyMetadata(default($type$)));$end$]]>
			</Code>
		</Snippet>
	</CodeSnippet>
</CodeSnippets>