Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 22-Oct-10 0:53am
v2
Comments
Dalek Dave 22-Oct-10 6:53am    
Edited for Readability.
Venkatesh Mookkan 22-Oct-10 7:39am    
It would be more easy for us to answer if you post some of the code.
Tarun.K.S 22-Oct-10 7:46am    
just a suggestion that, you could use a button and then apply a control template with a border or rectangle and then use triggers to highlight the border or the text. Well it will be much easier to do it!
Jibrohni 25-Oct-10 4:51am    
Here's my user control:

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

<grid.columndefinitions>
<columndefinition name="iconCol" width="100">
<columndefinition name="textCol" width="200">

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

<border name="bdrEdge" grid.columnspan="2" padding="20" borderthickness="1" borderbrush="Black" visibility="Hidden" panel.zindex="2">



Basically I require the border highlight event to trigger when the mouse enters the Grid's domain. This border needs to stay visible whilst also allowing for the mouseenter/mouseleave events to fire for the textblocks that I programmatically add to the textstackpanel.

But as the textblocks are the upper most entities, the grid loses it's mouseenter/mouseleave capabilities, hence no longer does the border show. And as the textblocks aren't always added in the same numbers per user control, there is quite often whitespace at the bottom of the usercontrol where the border doesn't fire if I try firing the event from the textblocks' mouseenter events.

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!
 
Share this answer
 
Comments
Tarun.K.S 25-Oct-10 9:25am    
ohkay! great!
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.
 
Share this answer
 
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>

 
Share this answer
 
How about giving Style.Triggers a try!
This is a Trigger part of the style:

<Style.Triggers>
<Trigger Property="MouseEnter" Value="True">
<Setter TargetName="txtStackPanel" Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
 
Share this answer
 
v3
Comments
Richard MacCutchan 25-Oct-10 6:45am    
Tarun, you just added a comment to my response to a question by Dale Seely, saying it was your code, so perhaps you could respond to his question. Thanks.
Tarun.K.S 25-Oct-10 9:25am    
i had given up Richard!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900