MouseEnter事件未触发-WPF [英] MouseEnter Event not firing - WPF

查看:109
本文介绍了MouseEnter事件未触发-WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个WPF应用程序,其中包含几个自定义用户控件.

我在透明矩形上有一个MouseEnter和MouseLeave事件,该事件使边框出现和消失以突出显示鼠标下的usercontrol.这很好.我遇到的问题是每个控件都包含一个自定义TextBlock,我希望将其链接到另一个突出显示其中文本的MouseEnter/Leave事件.

现在,矩形覆盖了该文本块,我认为这可能是自定义文本块的事件不触发的原因.
我该如何解决这个问题?
是z阶问题吗?

我以为即使触发器控件位于另一个控件之下,事件也会触发?

谢谢,

Jib

Hey all,

I''ve got a WPF app that contains several custom user controls.

I have a MouseEnter and MouseLeave event on a transparent rectangle that makes a border appear and disappear to highlight the usercontrol under the mouse. This works fine. The problem I''m having is each control contains a custom TextBlock that I wish to link to another MouseEnter/Leave event that highlights the text within it.

Now the rectangle covers this textblock and I think that this is perhaps the reason the events for the custom textblock don''t fire.

How can I get around this problem?
Is it a z-order problem?

I thought that the events would fire even if the trigger control is underneath another?

Thanks,

Jib

推荐答案

全部,

感谢所有的投入.像往常一样,问题出在我身上.我没有为网格设置背景这一事实意味着mouseenter/mouseleave事件不会触发.与z顺序无关.我将网格背景设置为透明且瞧瞧-工作已完成.

我是一个快乐的Jib!
All,

Thanks for all the input. The problem was me as per usual. The fact that I hadn''t set a background for the grid meant that the mouseenter/mouseleave events wouldn''t trigger. It was nothing to do with z-order. I set the grid background to transparent and voila - job done.

I''m a happy Jib!


当遇到类似这样的问题时,我不得不创建一个简单的测试应用程序以查看会发生什么.我建议您这样做是为了找到答案.

蠕虫具有重叠(但不完全重叠)的控件,并带有指定的鼠标enter事件.然后在两个事件处理程序方法中都带有断点的调试器下运行它.
When I come up against stuff like this, I resort to creating a simple test application to see what happens. That''s what I suggest you do to find your answer.

A worm with overlapping (but not completely overlapping) controls with the mouse enter event specified. Then run it under the debugger with breakpoints in both event handler methods.


XAML用户控件的重新发布:

Re-post of XAML User Control:

<pre lang="xml"><UserControl x:Class="BT_Control_Panel_1._1___User_Control.User_Controls.OptionControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300" Width="300">
        <Grid Name="mainOptionGrid">
        <Grid.RowDefinitions>
            <RowDefinition Name="row1"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Name="iconCol" Width="100"></ColumnDefinition>
            <ColumnDefinition Name="textCol" Width="200"></ColumnDefinition>
        </Grid.ColumnDefinitions>
            <Image Name="iconImage" Width="50" Height="50" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="25,6,25,0" Panel.ZIndex="1">
            <!--Icon to be inserted here-->
        </Image>
        <StackPanel Name="textStackPanel" Grid.Column="1" Width="200" Panel.ZIndex="1">
            <!--Add in custom textblocks here. First addition should be the header-->
        </StackPanel>
        <Border Name="bdrEdge" Grid.ColumnSpan="2" Padding="20" BorderThickness="1" BorderBrush="Black" Visibility="Hidden" Panel.ZIndex="2"></Border>
    </Grid>
</UserControl>



这篇关于MouseEnter事件未触发-WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆