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

  • Question

  • 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?

               
    • Moved by CoolDadTx Thursday, August 6, 2020 2:16 PM WPF related
    Thursday, August 6, 2020 1:21 AM

All replies