I
I
Ignatiy22019-11-03 09:58:44
WPF
Ignatiy2, 2019-11-03 09:58:44

How to set the minimum width of a button (not its content)?

My button is in a Grid. When I set MinWidth the minimum width for the button's content is determined (Content)

<Window x:Class="Encryption.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Encryption"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="63*" />
            <RowDefinition Height="31*" />
            <RowDefinition Height="46*" />
            <RowDefinition Height="47*" />
            <RowDefinition Height="46*" />
            <RowDefinition Height="47*" />
            <RowDefinition Height="47*" />
            <RowDefinition Height="46*" />
            <RowDefinition Height="46*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="88*" />
            <ColumnDefinition Width="61*" />
            <ColumnDefinition Width="115*" />
            <ColumnDefinition Width="88*" />
            <ColumnDefinition Width="88*" />
            <ColumnDefinition Width="88*" />
            <ColumnDefinition Width="88*" />
            <ColumnDefinition Width="61*" />
            <ColumnDefinition Width="115*" />
        </Grid.ColumnDefinitions>
        <TextBox HorizontalContentAlignment="Center"  VerticalContentAlignment="Center" TextWrapping="Wrap" RenderTransformOrigin="0.5,0.5" Background="White" x:Name="InputText" Grid.Column="3" Grid.ColumnSpan="3" Grid.Row="1"/>
        <Button Content="Зашифровать" FontSize="15" x:Name="EncryptionButton" Click="EncryptionButton_Click" Grid.ColumnSpan="3" Grid.Column="3" Grid.Row="3"/>
        <ComboBox HorizontalContentAlignment="Center"  VerticalContentAlignment="Center" Grid.Row="1" MinWidth="61" Grid.Column="1">
            <Label Content="C"/>
            <Label Content="D"/>
            <Label Content="E"/>
            <Label Content="F"/>
            <Label Content="G"/>
        </ComboBox>
        <Label Content="" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Margin="0,1,0,0"  FontSize="25" x:Name="Result" Grid.ColumnSpan="7" Grid.Row="5" Background="White" Grid.Column="1"/>
    </Grid>
</Window>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Space Purr, 2019-11-03
@Ignatiy2

Use the MinWidth property on the Window class, not the Button.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question