モノトーンの伝説日記

Apex Legends, Splatoon, Programming, and so on...

<mini> なんで `propdp` ってデフォルトで ownerClass 指定しないといけないままになってるんだろう

 直そうよ?

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>DependencyProperty を定義します</Title>
            <Shortcut>propdp</Shortcut>
            <Description>DependencyProperty をバッキング ストアとして使用するプロパティのコード スニペット</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>type</ID>
                    <ToolTip>プロパティの種類</ToolTip>
                    <Default>int</Default>
                </Literal>
                <Literal>
                    <ID>property</ID>
                    <ToolTip>プロパティ名</ToolTip>
                    <Default>MyProperty</Default>
                </Literal>
                <Literal default="true" Editable="false">
                    <ID>ownerclass</ID>
                    <ToolTip>このプロパティを所有しているクラスです。通常は、対応する宣言が存在するクラスです。</ToolTip>
                    <Function>ClassName()</Function> 
                    <Default>ownerclass</Default>
                </Literal>
                <Literal>
                    <ID>defaultvalue</ID>
                    <ToolTip>このプロパティの既定値です。</ToolTip>
                    <Default>0</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[

public $type$ $property$
{
    get { return ($type$)base.GetValue($property$Property); }
    set { base.SetValue($property$Property, value); }
}

// Using a DependencyProperty as the backing store for $property$.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty $property$Property
    = DependencyProperty.Register(nameof($property$), typeof($type$), typeof($ownerclass$), new PropertyMetadata($defaultvalue$));

$end$]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

 これで、ownerClass は自動で入るんで格段に入力が楽になります。

 ほかにも SimpleTypeName( TypeName ) みたいな関数があって、こいつは using 見てうまい具合に調整してくれるようになります。

<Literal Editable="false">
  <ID>SystemConsole</ID> 
  <Function>SimpleTypeName(global::System.Console)</Function> 
</Literal>

っていれたらいいですが、まあ上の依存関係プロパティーは DependencyObject が普通に読み込まれてるんで大丈夫でしょう?