Professional, Software

Fix for Button control

On forum, there was thread about button control affecting cursor behavior even when cursor is out of button and on the right. Here is the fix for it… It seems in the update layout method, one of the rectangles ( outlineHighlight) that constitute visuals for the button is not updated.

<Rectangle x:Name="outlineHighlight" Width='115' Height='20' RadiusX="10" RadiusY="10" Opacity="0">

This means there is a part of button hanging outside visual boundary of the button and that capture the mouseover behavior. Fix is pretty straight forward because all you have to do is update that rectangle when button height and width changes.

Member Variable

In the Button.cs file for button class you need to add member variable for the rectangle.

    public class Button : ButtonBase 
    { 
        Rectangle outlinehighlight; 

Get a Reference to the Rectangle

Find that Rectangle in the button constructor using FindName API

public Button() 
{ 
    text = (TextBlock)FindName("text"); 
    dimlight = FindName("dimlight") as Rectangle; 
    outline = FindName("outline") as Rectangle; 
    highlight = FindName("highlight") as Rectangle; 
    outlinehighlight = FindName("outlineHighlight") as Rectangle; 
} 

UPdate Updatelayout method

Update the rectangle height and width etc  in UpdateLayout method for the button class.

if (outline != null) { 
    outline.Width = Width; 
    outline.Height = Height; 
    outline.RadiusX = outline.RadiusY = Height / 2; 
    outlinehighlight.Height = Height; 
    outlinehighlight.Width = Width; 
    outlinehighlight.RadiusX = outline.RadiusX; 
}

Advertisements
Standard

3 thoughts on “Fix for Button control

  1. Pingback: Recursive Reflection : Fix for Button Control

  2. I do consider all the ideas you have presented to your post. They’re really convincing and will certainly work. Nonetheless, the posts are very brief for beginners. May you please lengthen them a little from next time? Thank you for the post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s