WPF:按钮宽度不能变小

WPF: button width cannot be changed smaller

在我的 WPF 应用程序的 windows 之一中,无论我做什么,按钮宽度都无法更改为更小的尺寸。我尝试更改 xaml 中 "width" 的 属性,在设计器中拖动按钮,或使用 c# 实用地更改它。即使我在window里面新建了一个按钮,宽度也只能变大,不能变小。尽管没有错误或警告,但 none 种方法成功更改了宽度。奇怪的是,我可以通过拖动轻松地将按钮的高度变小或变大,而在我的另一个 window 中,我可以轻松地变小或变大按钮的宽度和高度。我对所有 windows 中的所有按钮使用相同的样式。如果我拖动按钮,除非我解锁它周围的小 "knot",否则它不会有任何响应,但它看起来像这样:

唯一不足的是我为此window使用了通知模板,并且有一些动画效果。但我没有看到它和其他人有什么大的区别。这是 XAML 代码:

<Window x:Class="Timebreak.NotiWindow"
    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:Timebreak"
    mc:Ignorable="d"
    Title="TimeBreak" Height="450" Width="450"
    WindowStyle="None" AllowsTransparency="True" Opacity="0.7" Background="#f9f9ff"
    WindowStartupLocation="Manual" Left="0" Top="0">

<Grid>
    <Button x:Name="button1" Content="OK" Margin="358,341,13,72" Click="Submit_Click" FontSize="16" VerticalAlignment="Top" HorizontalAlignment="Left"/>
    <RadioButton x:Name="radioButton" Content="Yes. I want to stand up and take a break for (minutes)" HorizontalAlignment="Left" Height="26" Margin="31,105,0,0" VerticalAlignment="Top" Width="368" Checked="radioButton_Checked" FontSize="14"/>
    <RadioButton x:Name="radioButton1" Content="No. I don't want to stand up and take a break because" HorizontalAlignment="Left" Margin="31,206,0,0" VerticalAlignment="Top" FontSize="14" Checked="radioButton1_Checked"/>
    <Slider x:Name="slider" HorizontalAlignment="Left" Height="23" Margin="40,136,0,0" VerticalAlignment="Top" Width="374" IsSnapToTickEnabled="True" ValueChanged="slider_ValueChanged" Maximum="30" Minimum="1" Cursor="Hand" AutoToolTipPlacement="TopLeft" Interval="29" IsMoveToPointEnabled="True" TickPlacement="BottomRight"/>

    <!-- Animation -->
    <Grid.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)">
                        <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
                        <SplineDoubleKeyFrame KeyTime="0:0:4" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>

    <Grid.RenderTransform>
        <ScaleTransform ScaleY="1" />
    </Grid.RenderTransform>

</Grid>

请问有什么想法吗?提前致谢!

Does ideas about it?

您忘记了 post 您显然正在使用的自定义样式的标记,但您可以尝试设置 MinWidth 属性按钮到 0:

<Button x:Name="button1" Content="OK" Margin="358,341,13,72" Click="Submit_Click" FontSize="16" 
            VerticalAlignment="Top" HorizontalAlignment="Left" MinWidth="0"/>

如果仍然不能增加按钮的宽度,请 post 你的 XAML 标记和代码的所有相关部分。