How do you programmatically change the height of a button giving its width?

  • Thread starter Thread starter JohnGlen244
  • Start date Start date
J

JohnGlen244

Guest
This works for making a square button:

Height = "{Binding Path=ActualWidth, RelativeSource={RelativeSource Self}}"

I would like a aspect ratio of 1 to 5 though. Something like this:

Height = "{Binding Path=ActualWidth/5.0, RelativeSource={RelativeSource Self}}"


That does not compile though.


I have attempted to use c# to make a square button:

Button button = (Button)FindName("ButtonStart");
var myBinding = new Binding("Height")
{
Source = button.ActualWidth
};
button.SetBinding(Button.HeightProperty, myBinding);

This doesn't make the button square.

Is it possible to set the aspect ratio of a button using data binding?

Continue reading...
 
Back
Top