Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to use a style setter for properties of properties?
    primarykey
    data
    text
    <p><strong>Edit:</strong> <em>In the original question i made some wrong assumptions about how setters work so i modified it to hopefully be more accurate and useful.</em></p> <p>I have tried to make some menu items more interesting by having the icons appear half-transparent if the mouse is not over the item. If the mouse enters, the icon should be animated to become completely visible. The animations work, <code>Storyboard.TargetProperty</code> allows direct access to the icon's opacity property:</p> <pre><code>&lt;Style x:Key="MenuItemMouseOverStyle" TargetType="MenuItem"&gt; &lt;Style.Triggers&gt; &lt;EventTrigger RoutedEvent="MouseEnter"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Icon.Opacity"&gt; &lt;EasingDoubleKeyFrame KeyTime="0" Value="0.5"/&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;EventTrigger RoutedEvent="MouseLeave"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Icon.Opacity"&gt; &lt;EasingDoubleKeyFrame KeyTime="0" Value="1"/&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.5"/&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>If i try to use a setter for the initial icon-opacity the code won't compile:</p> <pre><code>&lt;Setter Property="Icon.Opacity" Value="0.5"/&gt; </code></pre> <hr> <p><strong>Edit:</strong> <em>Setters do not work the way i tried to use them, you cannot access the properties of properties (see answers) The only thing you can do is specify a target class if the target type of the style has not been set, the following styles should be equivalent:</em></p> <pre><code>&lt;Style x:Key="Style1" TargetType="Image"&gt; &lt;Setter Property="Opacity" Value="0.5"/&gt; &lt;/Style&gt; &lt;Style x:Key="Style2"&gt; &lt;Setter Property="Image.Opacity" Value="0.5"/&gt; &lt;/Style&gt; </code></pre> <hr> <p>So my question is if there is a way to make this somehow work with a setter.</p> <p>(My current work-around is a single-keyframe storyboard that is triggered with the <code>Loaded</code> event which works quite well)</p>
    singulars
    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.
 

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