Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Height/Width

In a custom WPF control I would like to set the width of the control to be a function of the Height. For example: Width = Height / 3 * x;

What would be the best way to accomplish this so that the control resizes (and initially sizes) correctly and fluidly?

like image 509
David Martin Avatar asked Sep 09 '26 14:09

David Martin


1 Answers

You could bind Width to ActualHeight, and use converter to apply custom function. E.g. the following code makes Button always squared:

<Button Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>

Hope this helps,

Cheers, Anvaka.

like image 91
Anvaka Avatar answered Sep 12 '26 10:09

Anvaka