1

iv'e got a "Cube" (Dice) control which derives from Button

Cube :

public class Cube : Button
{        
    public Cube()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(Cube), new FrameworkPropertyMetadata(typeof(Cube)));                                
    }
    ...... // Stuff
}

Template (In general):

<ControlTemplate TargetType="{x:Type local:Cube}" x:Key="CubeControlTemplate">
         <Border>                
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Border>
                        <Grid>
                            .......
                        </Grid>                          
                    </Border>

                    <Border Grid.Column="2">
                        <Grid>
                            .......
                        </Grid>                          
                    </Border>    
              <Grid> 
        </Border> 
</ControlTemplate>

what it looks like :

enter image description here

the yellow marking shows that it is clickable only behind the Content , only if you really target your click where the Button is "Hidden" ..

any ideas why this happens ?

eran otzap
  • 12,293
  • 20
  • 84
  • 139

2 Answers2

6

Without a Background mouse events will not be catched. Give your outer Border a transparent Color:

<ControlTemplate TargetType="{x:Type local:Cube}" x:Key="CubeControlTemplate">
    <Border Background="Transparent">                
        .......
    </Border> 
</ControlTemplate>
LPL
  • 16,827
  • 6
  • 51
  • 95
0

Please check that you are not trying to click on an element that has a Null background. Hit testing requires a Brush to be set.

If your Border or your Grid has a Null background try setting it to Transparent.

If you are still having issues try debugging with Snoop.

http://snoopwpf.codeplex.com/

Alex Wiese
  • 8,142
  • 6
  • 42
  • 71
  • 1
    A transparent Background is not the problem but Background=null. – LPL Oct 07 '12 at 22:39
  • iv'e observed it with snoop , i believe @LPL is correct which is the opposite of what your describing , i add a similar problem in the past and i forgot this is an issue . appreciate the quick response though. :) – eran otzap Oct 07 '12 at 22:41
  • Hit testing requires a Brush to be set, not {x:Null}. – Alex Wiese Oct 07 '12 at 22:41
  • By default a brush will have a value of {x:Null} you need to apply a brush to the element to make it hit test visible. http://stackoverflow.com/questions/5344699/xnull-vs-transparent – Alex Wiese Oct 07 '12 at 22:42