Print Page | Close Window

Triggers for individual objects

Printed From: Codejock Forums
Category: General
Forum Name: XAML Snippets
Forum Description: Post your XAML snippets here for everyone to enjoy :)
URL: http://forum.codejock.com/forum_posts.asp?TID=15960
Printed Date: 21 May 2024 at 6:03am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Triggers for individual objects
Posted By: jpbro
Subject: Triggers for individual objects
Date Posted: 06 January 2010 at 10:26am
I've looked over the documentation & triggers.xaml sample, and I understand how to apply a trigger to all objects of a class (for example, all rectangles can become green on mouseover). What I would like to do is set a trigger for a particular object only, for example:

I have a StackPanel with 3 images. I would like to be able to change the Source property for only one of those images on mouse over (and restore the previous Source on mouse leave). I imagine I have to do something with the Key property, but nothing I have tried so far works.

Does anyone know how to do this? Thanks a lot in advance.


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6




Replies:
Posted By: jpbro
Date Posted: 06 January 2010 at 11:03am
Sometimes just asking the question inspires the answer - I was thinking of it backwards (that the x:Key property of the style would be the same as a key property of the object). Instead we can assign the {StaticResource KEY} to the Style property of the object. Something like:


<Page>
<Page.Resources>
    <Style x:Key='SwapImageIds' TargetType="Image">
        <Setter Property="Source" Value="102"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Trigger.Setters>
                    <Setter Property="Source" Value="103"/>
                </Trigger.Setters>
            </Trigger>
        </Style.Triggers>
    </Style>   
</Page.Resources>
   
<StackPanel>
        <Image Style='{StaticResource SwapImageIds}' />
        <Image Source='file://c:/SOMEIMAGE' />
</StackPanel>
</Page>


Only the first image will be affected by the triggers.

Another important thing to note is that you shouldn't define any properties that you want to affect by triggers in the object, otherwise the trigger won't work.


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net