Stackpanel IsMouseOver为False - 当鼠标超过stackPanel Items之间的间隙时

时间:2016-01-20 16:31:18

标签: c# wpf xaml

我有以下WPF控件

enter image description here

当应用程序运行时,它看起来像这样。

enter image description here

问题是 - 当鼠标位于按钮之间时,弹出窗口已关闭。 (U,B和NB按钮之间的差距)

正如您所看到的 - Popup.IsOpen属性绑定到stackPanel - IsMouseOver

我该如何解决这个问题?因此当我的鼠标位于所提到的按钮之间时,Popup会打开吗? (最好没有任何代码隐藏)

2 个答案:

答案 0 :(得分:6)

将StackPanel设置为Transparent(或任何适合您的颜色)。出于某种原因,设置背景画笔(甚至设置为透明)允许IsMouseOver按预期工作。可能有一些WPF魔术与布局和渲染优化。

    <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>

答案 1 :(得分:2)

所有面板的背景的默认值为null,当背景为null时,触摸和鼠标事件将不起作用。将stackpanel背景设置为透明或其他颜色。

相关问题