Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

xaml

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)

like image 770
Marty Avatar asked Jan 07 '23 19:01

Marty


2 Answers

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>
like image 199
Rowbear Avatar answered Jan 10 '23 12:01

Rowbear


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.

like image 24
Radin Gospodinov Avatar answered Jan 10 '23 12:01

Radin Gospodinov