wpf - Trigger for custom dependency properties in Style -


the problem

i defined reusable control, mycontrol, extends textbox.

i want set trigger 1 of dependency properties.
added style it, triggers.

but if set targettype of style mycontrol, xaml warning 'mycontrol' targettype not match type of element 'textblock'.
, if set textblock, compilation error the member "mydependencyproperty" not recognized or not accessible..

  • how can define style triggers?

sample

c# code-behind

namespace usercontrols.local {     public partial class mycontrol : textblock     {         #region trogdor          public static readonly dependencyproperty trogdorproperty = dependencyproperty.register(             "trogdor", typeof (bool), typeof (mycontrol), new propertymetadata(default(bool)));          public bool trogdor         {             { return (bool) getvalue(trogdorproperty); }             set { setvalue(trogdorproperty, value); }         }          #endregion           public mycontrol()         {             initializecomponent();         }     } } 

xaml

<textblock     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:local="clr-namespace:usercontrols.local"     mc:ignorable="d"     text="boop!"     x:class="usercontrols.local.mycontrol">     <textblock.style>         <style targettype="{x:type textblock}">             <setter property="foreground" value="blue"/>             <style.triggers>                 <trigger property="trogdor" value="true">                     <setter property="foreground" value="deeppink"/>                 </trigger>             </style.triggers>         </style>     </textblock.style> </textblock> 

the solution found "fully qualify" dependency property on binding:

<trigger property="local:mycontrol.trogdor" value="true"> 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -