✅ WPF MouseOver expansion of item isn't working

I have a window with a bar that needs to hide down to a separator until the user mouses over it or checks a checkbox (which pins the bar to "open"). However, WPF seems to be claiming if the mouse is over the margin for the separator, it's not over the bar. The code is below.
<Grid
x:Name="gridExtended"
DockPanel.Dock="Bottom"
IsMouseDirectlyOverChanged="OnExtendedToolBarMouseDirectlyOverChanged">
<Grid.RowDefinitions>
<RowDefinition
Height="10" />
<RowDefinition
Height="{Binding ExtendedToolBarRowTwoHeight, ElementName=window, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" />
</Grid.RowDefinitions>
<Separator
VerticalContentAlignment="Center"
HorizontalContentAlignment="Stretch"
Grid.ColumnSpan="25"
Height="1" />
<Grid
x:Name="gridExtended"
DockPanel.Dock="Bottom"
IsMouseDirectlyOverChanged="OnExtendedToolBarMouseDirectlyOverChanged">
<Grid.RowDefinitions>
<RowDefinition
Height="10" />
<RowDefinition
Height="{Binding ExtendedToolBarRowTwoHeight, ElementName=window, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" />
</Grid.RowDefinitions>
<Separator
VerticalContentAlignment="Center"
HorizontalContentAlignment="Stretch"
Grid.ColumnSpan="25"
Height="1" />
public System.Windows.GridLength ExtendedToolBarRowTwoHeight
{
get
{
if(gridExtended == null || chkExtendedToolBarShow == null)
System.Diagnostics.Debug.WriteLine("Nulls");
else
System.Diagnostics.Debug.WriteLine($"Extended: {gridExtended.IsMouseDirectlyOver
}\tCheckbox: {chkExtendedToolBarShow.IsChecked}");
return gridExtended != null && chkExtendedToolBarShow != null && (gridExtended.IsMouseDirectlyOver
|| chkExtendedToolBarShow.IsChecked == true) ? System.Windows.GridLength.Auto : new
(0);
}
}
public System.Windows.GridLength ExtendedToolBarRowTwoHeight
{
get
{
if(gridExtended == null || chkExtendedToolBarShow == null)
System.Diagnostics.Debug.WriteLine("Nulls");
else
System.Diagnostics.Debug.WriteLine($"Extended: {gridExtended.IsMouseDirectlyOver
}\tCheckbox: {chkExtendedToolBarShow.IsChecked}");
return gridExtended != null && chkExtendedToolBarShow != null && (gridExtended.IsMouseDirectlyOver
|| chkExtendedToolBarShow.IsChecked == true) ? System.Windows.GridLength.Auto : new
(0);
}
}
What's going on? It should work so that the bar stays open if the mouse is anywhere over the bar, not just the separator.
8 Replies
JakenVeina
JakenVeina7mo ago
can I get a screenshot of the layout in question? I'm having trouble visualizing what you describe
Will Pittenger
Will Pittenger7mo ago
Do these help?
No description
No description
No description
JakenVeina
JakenVeina7mo ago
okay, so hovering over the separator should toggle the bar? try giving the Grid a background of Transparent
Will Pittenger
Will Pittenger7mo ago
No, hovering over anywhere in its parent should reveal the rest of the bar. Only the separator is visible. The separator has a margin that should also cause the bar to expand.
JakenVeina
JakenVeina7mo ago
as opposed to a background of null
Will Pittenger
Will Pittenger7mo ago
I did.
JakenVeina
JakenVeina7mo ago
uhhh well
Unlike IsMouseOver, this property is only true if the mouse pointer is over the literal element - as it is for a hit test. If the mouse pointer is instead over a child element, in particular over elements that are part of an element's deeper template and compositing, this property will be false.
Unlike IsMouseOver, this property is only true if the mouse pointer is over the literal element - as it is for a hit test. If the mouse pointer is instead over a child element, in particular over elements that are part of an element's deeper template and compositing, this property will be false.
use IsMouseOver
Will Pittenger
Will Pittenger7mo ago
I found out about that after I started the thread. So it's not shown. Ah. That did it. Thank you.
Want results from more Discord servers?
Add your server
More Posts