Recently, I have been given the following task from my boss :-
"Give me a button that takes on the shape of my image. The image can have transparent regions. When a transparent region is clicked, the onclick code should not run"
So what have I done so far? - I have created an image with transparent regions and done
ImageBrushsampleBrush = new ImageBrush();
Uri uri = new Uri("C:\\test1.png");
BitmapImage SamplePic = new BitmapImage(uri);
sampleBrush.ImageSource = SamplePic;
button1.Background = sampleBrush;
this gets the appearance looking good. I.e from a user point of view my button has taken on the shape of the image. All well and good.
However, the behaviour isnt quite there. When I click on a transparent part of the button, I do not want the onclick code to run. At present I am getting round this by running a method that scans the image to make up a Clip for my button.
Works OK but is very slow as its scanning the image pixel by pixel!!
Yes, I could check to see if the area I'm clicking on is transparent or not everytime the button is clicked, but I dont want to have to add this code for every type of button I may create in the furure.