MouseEnter事件未触发

MouseEnter事件未触发

本文介绍了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

推荐答案



<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:01