[WPF] Change the text in the Button according to the Button size

less than 1 minute read

Introduction

When you put a button in a window that can be resized in WPF
How to change the text size according to the button size.
Not only the text but also the buttons inside the buttons are fine. (I think it’s rare …)

I didn’t know the existence of ViewBox
If there is a similar person.

Method

MainWindow.xaml


<Window ~~~abridgement~~~ >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Button Grid.Row="0">
            <Viewbox>
                <TextBlock>Variable size</TextBlock>
            </Viewbox>
        </Button>
        <Button Grid.Row="1">
Fixed size
        </Button>
    </Grid>
</Window>

Tags: ,

Updated: