Link to home
Start Free TrialLog in
Avatar of vamail2
vamail2

asked on

WPF - Menu Triggers and AStyles

I was looking for the best way through XAML to change the background color of a textbox when I am hovering over a particular menu item in the mainwindow (and then it should return back to normal).  I realize this is simple but I wasn't getting it to work.
Avatar of Snarf0001
Snarf0001
Flag of Canada image

I would use a style trigger on the textbox, bound to the IsMouseOver property of the desired menu item.
<TextBox Text="my text here" Width="150">
    <TextBox.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=<<my label name>>, Path=IsMouseOver}" Value="True">
                    <Setter Property="Control.Background" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of vamail2
vamail2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vamail2
vamail2

ASKER

Awesome.  Thanks.
No problem.  When I started with WPF I used "WPF Programmer's Reference" from wrox.
Gives a really good starting point and a lot of detailed features.
The Microsoft documentation is atrocious, once you get comfortable with WPF in general, other non-ms examples online are very helpful.

It can be a bit tricky off the start, since there's half a million different ways to do the same thing, but all I can say is the more you do it, the more intuitive it becomes.

By FAR my favorite proejcts to work on now are WPF.
Avatar of vamail2

ASKER

*whoops* I made a mistake.  I meant to close this on snarf's comments not mine
Avatar of vamail2

ASKER

How do I fix this and properly assign points and close based on Snarf's ccomments