Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Make "invisible" area clickable in custom control

$
0
0

Greetings,

I got a custom control which looks like similar to a thin line. The custom control itself should be clickabel, but it's difficult to click on the customcontrol when the Size of the control is Width=1 Height 0,5. So I thought I can tell the control to be larger as it is.

I thought it can be done with this: 

        protected override Size MeasureOverride(Size constraint)
        {
            //add some extra space for better selecting the item (IsMouseover, OnClick usw)
            return base.MeasureOverride(new Size(constraint.Width+5,constraint.Height+10));
        }

But actualy it seems that it doesn't effect what I want. You have to click/mouseover exactly over the line.

What is wrong with my code?

Here my custom control which should be easy clickabel:

<Style TargetType="{x:Type local:Edge}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type local:Edge}"><Grid><Grid.ColumnDefinitions><ColumnDefinition  /><ColumnDefinition  /></Grid.ColumnDefinitions><Line Stroke="{TemplateBinding Foreground}"  Grid.Column="0"  StrokeThickness="{TemplateBinding StrokeThickness}"
                        X1="{Binding Mode=TwoWay,Path=PositionU.X,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:Edge}}}"
                        Y1="{Binding Mode=TwoWay,Path=PositionU.Y,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:Edge}}}"
                        X2="{Binding Mode=TwoWay,Path=PositionV.X,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:Edge}}}"
                        Y2="{Binding Mode=TwoWay,Path=PositionV.Y,UpdateSourceTrigger=PropertyChanged,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:Edge}}}" ></Line></Grid></ControlTemplate></Setter.Value></Setter></Style>

Best regards


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>