Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Cannot Get Custom Attached Property to work as a Trigger Property
    text
    copied!<p>So I have a class that looks like this:</p> <pre><code>internal class MyClass { public static readonly DependencyProperty IsSomethingProperty = DependencyProperty.RegisterAttached( "IsSomething", // property name typeof(bool), // property type typeof(MyClass), // owner type 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); } } </code></pre> <p>I would like to be able to use this attached property as a trigger property in a control template, like so:</p> <pre><code>&lt;ControlTemplate TargetType="TreeViewItem"&gt; &lt;!-- stuff here omitted for brevity --&gt; &lt;Trigger Property="my:MyClass.IsSomething" Value="True"&gt; &lt;!-- setters for when IsSomething is True --&gt; &lt;/Trigger&gt; &lt;/ControlTemplate&gt; </code></pre> <p>(the above control template assumes the proper <code>xmlns:my="clr-namespace:MyAssembly"</code> where MyAssembly contains MyClass is in the enclosing XAML file)</p> <p>Here's my trouble: when I do this, it compiles fine. However, when I try to see this control template in action in the designer, it complains <code>Cannot find the 'IsSomething' template property on type 'System.Windows.Controls.TreeViewItem'.</code> and the designer won't load.</p> <p>I've tried the <code>RegisterAttached</code> override with <code>MyClass</code> as well as <code>TreeViewItem</code> as the owner type, neither fixes this. I've also tried it with and without the <code>AttachedPropertyBrowsableForType</code> attribute on <code>GetIsSomething</code>. Does anyone see what the problem is?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload