how to solve issue when MouseEnter/MouseOver after Focus fires up in xaml?

52 Views Asked by At

Hello everyone!, i need your help with this problem, i'm trying to build my first app with WPF and XAML language, and also C# involved with them, so the issue here that i have a TextBox and this textbox have a custom Style, and in this style every thing working good, except of the ControlTemplate.Triggers, inside it, i was trying to make the textbox when MouseEnter or MouseOver to change it's color with a ColorAnimation, and it worked without problems, and now i have it changing the color with animation to some another color when mouse is over, and get back to the default color when mouse not over the textbox, oke.. now i need to make the button when i click it change it's color to be lighter while focusing on the textbox, to be different from the others, witch means that now this is the current activated or focused textbox, and when i traied to do it i was making it changing the color from the color that occur when mouse is over = true, to another lighter color in the ExitActions, so it stay at that color tell focus is change to another thing, but here is the problem: after losing focus and geting back to the Default color of the textbox by clicking a button or anything else, eveytime when i try after that to make it's color changing on the colors that was set with the MouseEnter/IsMouseOver event occur, there is nothing happening, when i put mouse over the textbox nothing occur or happen, and the same when mouse leaves the textbox, and here's the problem i traied to solve for days, and i don't know how to do that and to solve it, Sorry if i talked too match, but i just wanted to make things clear about what i'm trying to do.

and for the ControlTemplate.Triggers code in xaml, here is this code:

<ControlTemplate.Triggers>

                        <EventTrigger RoutedEvent="MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetProperty="Background.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.2" 
                                                        To="#777777">

                                    </ColorAnimation>
                                    <ColorAnimation Storyboard.TargetProperty="BorderBrush.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.2" 
                                                        To="#666666">

                                    </ColorAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetProperty="Background.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.2" 
                                                        To="#676767">

                                    </ColorAnimation>
                                    <ColorAnimation Storyboard.TargetProperty="BorderBrush.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.2" 
                                                        To="#5b5b5b">

                                    </ColorAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        
                        <EventTrigger RoutedEvent="MouseDown">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetProperty="Background.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.1" 
                                                        To="#777777">

                                    </ColorAnimation>
                                    <ColorAnimation Storyboard.TargetProperty="BorderBrush.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.1" 
                                                        To="#666666">

                                    </ColorAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="MouseUp">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetProperty="Background.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.5" 
                                                        To="#676767">

                                    </ColorAnimation>
                                    <ColorAnimation Storyboard.TargetProperty="BorderBrush.Color" 
                                                        Storyboard.TargetName="border" 
                                                        Duration="0:0:0.3" 
                                                        To="#5b5b5b">

                                    </ColorAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>

                        


                    </ControlTemplate.Triggers>

By the way, i've traied a lot of things like using IsFocused Property, MultiCondition, and more else, i hope some one could help me soon as possible with this problem, and thank you.

MouseOver/MouseEnter, after losing focus of the textbox not working and not occurs.

0

There are 0 best solutions below