Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Custom Attached Property in Style Trigger with Setter
    primarykey
    data
    text
    <p>I was trying out attached properties and style triggers hoping to learn more about it. I wrote a very simple WPF windows app with an attached property:</p> <pre><code> public static readonly DependencyProperty SomethingProperty = DependencyProperty.RegisterAttached( "Something", typeof(int), typeof(Window1), new UIPropertyMetadata(0)); public int GetSomethingProperty(DependencyObject d) { return (int)d.GetValue(SomethingProperty); } public void SetSomethingProperty(DependencyObject d, int value) { d.SetValue(SomethingProperty, value); } </code></pre> <p>And I was trying to update the 'Something' attached property with a property trigger defined in the button style section:</p> <pre><code> &lt;Window x:Class="TestStyleTrigger.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestStyleTrigger;assembly=TestStyleTrigger" Title="Window1" Height="210" Width="190"&gt; &lt;Window.Resources&gt; &lt;Style x:Key="buttonStyle" TargetType="{x:Type Button}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsPressed" Value="True"&gt; &lt;Setter Property="local:Window1.Something" Value="1" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Button Style="{StaticResource buttonStyle}"&gt;&lt;/Button&gt; &lt;/Window&gt; </code></pre> <p>However, I kept getting following compilation error:</p> <p>error MC4003: Cannot resolve the Style Property 'Something'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property. Line 10 Position 29.</p> <p>I can't understand why it gives me this error because I did use the 'Class.Property' syntax in the tag of the section. Can any one tell me how can I fix this compilation error?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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