views:

30

answers:

1

I have a control which expands when IsMouseOver is set to true using a trigger. Within that control, there is some textboxes that have some basic validation. My problem is that when a validation error occurs and the user mouses over the Red border around the textbox (almost guarenteed to happen as user moves the mouse to center of textbox to change the value), the IsMouseOver gets set to false and the control closes.

Validation Error for Textboxes:

<Style TargetType="{x:Type TextBox}">
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
            <Setter Property="ToolTip" Value="{Binding 
                Path=(Validation.Errors)[0].ErrorContent, 
                RelativeSource={x:Static RelativeSource.Self}}" />
        </Trigger>
    </Style.Triggers>
</Style>

Trigger to show control:

<DataTrigger Binding="{Binding ElementName=TabControl_TabPanel, Path=IsMouseOver}" Value="True">
    <Setter Property="Visibility" Value="Visible" />
</DataTrigger>

UPDATE: IsMouseOver is also getting set to False when I right-click a textbox and open the context menu

A: 

In the case of the context menu, things are pretty clear: it is a different window (at a low level), so your control cannot possibly detect anything 'though' it. Likewise, validation errors in WPF are displayed in a complicated and convoluted manner, and suffice it to say they are not really part of your control either.

I'd suggest using focus events for your scenario; is mouse-over really required? There may be some ways to make it work though...

Alex Paven
I guess it was something else.... The control is a "sliding" panel where the tab is on the edge of the screen and moving your mouse over it makes the control slide out and display its content. I guess I'll see if I can find an alternative way of putting it together.
Rachel
I reworked the code to set visibility based on MouseEnter/MouseLeave. In the MouseLeave event I checked to see if the mouse position was still within the bounds of the control and left the control visible if it was.
Rachel