How to remove the border of a Button in code?

6k views Asked by At

I am developing a windows phone 7 application. I am new to windows phone 7 applications. In my application I have created a button control dynamically and added the background image to the button control as follows.

Button AlphabetButton = new Button();
                AlphabetButton.Content = vAlphabet;
                ImageBrush brush = new ImageBrush();
                brush.ImageSource = new BitmapImage(new Uri("button_off.png", UriKind.Relative));
                //brush.Stretch = Stretch.None;
                AlphabetButton.Background = brush;
                AlphabetButton.BorderBrush = new SolidColorBrush(Colors.Gray);

                AlphabetButton.Margin = new Thickness(-12, -27, 0, 0);
                AlphabetButton.Width = 80;
                AlphabetButton.Height = 80;     

I want to remove the border of the button control because with that border the image does not appear as per requirement. How to do this? Can we do this with the BorderThickness attribute of button control or is there any other way? Can you please provide me any code or link through which I can resolve the above issue? If I am doing anything wrong then please guide me.

2

There are 2 answers

0
Boryana Miloshevska On BEST ANSWER

The easiest way is to set the BorderThickness to 0 like for Example:

            Button alphabetButton = new Button();
            alphabetButton.BorderThickness = new Thickness(0.0);

Another option could be to set the BorderBrush to Transparent or to change the whole Style of the button and especially its ControlTemplate.

1
Thanigainathan On

I think Button.StrokeTHickness is the correct property to adjust the borders.