依存関係プロパティと添付プロパティ 実験編
という事で、本当に添付プロパティが依存関係プロパティでなくても良いかを試すコードを書いてみました。
まずは添付プロパティです。
public class CMyWindow : System.Windows.Window
{
public static void SetTest(UIElement element, string value)
{
}
public static string GetTest(UIElement element)
{
return "";
}
}
こうする事で、「Test」という添付プロパティが使えるはずです。
次はXAML
<local:CMyWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestProject"
xml:lang="ja-JP"
x:Class="TestProject.Window1"
x:Name="CMyWindow"
Title="Window"
Width="640" Height="480">
<StackPanel>
<Button Content="Test" local:CMyWindow.Test="abc" />
</StackPanel>
</local:CMyWindow>
こんな感じで、CMyWindowのTest添付プロパティをButtonコントロールの中で設定します。
という事で、これをテストしてみましたら…なんとうまくいきました。
もちろん、SetTest,GetTestの中身は空なのですが、すくなくとも、依存関係プロパティでなくてもコンパイルは通るみたいです。
| 固定リンク
「WPF」カテゴリの記事
- WPFでバインディングができない(2007.10.04)
- いまさらバインディング(2007.10.02)
- 依存関係プロパティと添付プロパティ(2007.08.14)
- 依存関係プロパティと添付プロパティ 実験編(2007.08.16)
- 次の壁(2007.04.13)


コメント