In WPF, can I somehow use TemplateBinding to set the CornerRadius of a templated Button?

601 Views Asked by At

I have a Button ControlTemplateemplate that I'd like to reuse, except for the CornerRadius of its Border, which I'd like to get from TemplatedParent so I can specify it in the Button declaration.

Unfortunately, CornerRadius is not a property of Button, so the compiler doesn't like it.

I see a couple ways I could pull it off, but I don't really like them.

  1. Misuse a field I'm not otherwise using (say, MinWidth?) to communicate this new radius. Not sure if this'll work since an int is not exactly a CornerRadius.
  2. Make a subclass of Button to add CornerRadius and use that.

Is there another approach I might be missing?

1

There are 1 best solutions below

1
On BEST ANSWER

The only other thing I could think of would be creating an AttachedProperty for CornerRadius and attaching that to the button, then binding to that. I'm not sure if binding to the AttachedProperty will work through TemplatedParent though.

Also, it's probably less code just to create a derived Button class than it is to create an AttachedProperty. So it might not be worth it.