Codejock Forums Homepage
Forum Home Forum Home > General > XAML Snippets
  New Posts New Posts RSS Feed - Triggers for individual objects
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Triggers for individual objects

 Post Reply Post Reply
Author
Message
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Topic: Triggers for individual objects
    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

Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.