So, I have a class that looks like this:
internal class MyClass
{
public static readonly DependencyProperty IsSomethingProperty =
DependencyProperty.RegisterAttached(
"IsSomething",
typeof(bool),
typeof(MyClass),
new FrameworkPropertyMetadata(false)
);
public static void SetIsSomething(DependencyObject obj, bool value)
{
obj.SetValue(IsSomethingProperty, value);
}
[AttachedPropertyBrowsableForType(typeof(TreeViewItem))]
public static bool GetIsSomething(DependencyObject obj)
{
return (bool)obj.GetValue(IsSomethingProperty);
}
}
I would like to be able to use this nested property as a trigger property in a control template, for example:
<ControlTemplate TargetType="TreeViewItem">
<Trigger Property="my:MyClass.IsSomething" Value="True">
</Trigger>
</ControlTemplate>
(the above control template assumes the correct one xmlns:my="clr-namespace:MyAssembly", where MyAssembly contains MyClass in the attached XAML file)
Here is my problem: when I do this, it compiles fine. However, when I try to see this control pattern in action in the constructor, it complains about Cannot find the 'IsSomething' template property on type 'System.Windows.Controls.TreeViewItem'., and the constructor does not load.
RegisterAttached MyClass, TreeViewItem , . AttachedPropertyBrowsableForType <<28 > . - , ?