The best idea so far is the Solution 4.
The right solution for
is: create a custom control which behaves like a button and implement rotation property. If you want to rotate to an arbitrary angle, you should also set the property
As Maciej expressed his concerns about first solution, I'll provide some mode detail.
In case of arbitrary angle, it's a bit complicated, and I didn't want to spend so much time for more complicated code at first.
Basically, you need to have a bigger control which fits the full set of buttons at all angles; it would be a round area, and you should draw a rectangle around the round. Can you picture such figure? Inside this area, you can draw a rectangular button at any angle. Now, you render the whole button in all the detail, including borders, using
, depending on the current angle.
Now, you need to cut out unused part of the control. To do so, you calculate the rectangular Region representing the tilted button and assign this region to
property of the control.
Now, how to change the angle? The
property should have a setter
to do all the side effects of changing the value. If the value is different from the previous value, you should to two things 1) create a rectangular region at different angle and re-assign the property
of the control; 2) call
to cause re-drawing of the control.
[END EDIT #2]
If you only want to allow only 90°, the problem is especially simple. Derive the button class from
. First, switch from horizontal to vertical position is done view swapping
values. It will correctly render non-client area of the button.
Render the client area in the overridden method
. You need to render the text rotated. For rotation, use
(you will get the instance of
from an event arguments parameter):