Search code examples
c#xamltransformscaleresolution

Automatic button scaling based on window size C#/XAML


i'm fairly new at this so i apologize in advance if i say anything stupid.

I am making a UI in WPF that consists of 8 buttons to open various programs set on my computer. Currently i am trying to get the buttons in the UI to scale based on the detected window size.

The problem i am having is trying to get the calculations done in the C# code to link over to the scale transform option for the buttons in XAML.

I have searched high and low to find a solution but i still cannot find a way to link the value to XAML. Does anyone know of a guide for something like this and should it be done using a converter?

Thanks for any help.


Solution

  • When you need your content to autoscale, put it all into a ViewBox control.

    <Window>
       <Viewbox>
          <Grid x:Name = rootGrid>
          </Grid>
       </Viewbox>
    </Window>
    

    Now everything will magically fill to the window size and scale! Instant awesomeness for your app.