Marty
Marty

Reputation: 3555

Stackpanel IsMouseOver is False - when mouse is over the gap between stackPanel Items

I have the following WPF control

enter image description here

And it looks like this when the app is running.

enter image description here

The problem is - that the popup - is Closed when my mouse is between the buttons. (the gap between the U, B & NB buttons)

As You can see - Popup.IsOpen property is bound to the stackPanel - IsMouseOver

How can I solve this ? So that the Popup would be open while my mouse is between the mentioned buttons ? (preferably without any code-behind)

Upvotes: 4

Views: 752

Answers (2)

Radin Gospodinov
Radin Gospodinov

Reputation: 2323

The default value for the backgound for all panels is null, and when the background is null the touch and mouse events will not work. Set the stackpanel background to transparent or other color.

Upvotes: 2

Rowbear
Rowbear

Reputation: 1669

Set the StackPanel to Transparent (or whatever color works for you). For some reason, setting the Background brush (even to Transparent) allows the IsMouseOver to work as you would expect. Likely some WPF magic with layout and rendering optimization.

    <Grid>
        <StackPanel x:Name="ThePanel" Background="Transparent">
            <TextBox Margin="5">WOOT</TextBox>
            <TextBox Margin="5">WOOT</TextBox>
            <TextBox Margin="5">WOOT</TextBox>
        </StackPanel>

        <Popup IsOpen="{Binding ElementName=ThePanel, Path=IsMouseOver, Mode=OneWay}">
            <!--stuff-->
        </Popup>
    </Grid>

Upvotes: 7

Related Questions