WPF:按钮宽度不能更改得更小
在我的WPF应用程序的一个窗口中,无论我做什么,都不能将按钮宽度更改为更小的大小。我尝试在xaml中更改“width”的属性,在designer中拖动按钮,或者使用c#实用地更改它。即使我在该窗口中创建了一个新按钮,宽度也只能更改为较大的尺寸,但不能更改为较小的尺寸。虽然没有错误或警告,但没有一种方法成功地更改宽度。奇怪的是,我可以通过拖动轻松地将按钮的高度更改为更小或更大,而在我的另一个窗口中,我可以轻松地将按钮的宽度和高度更改为更小或更大。我对所有窗口中的所有按钮使用相同的样式。如果我拖动按钮,将不会有任何响应,除非我解锁它周围的一个小“结”,但它将如下所示: 唯一的问题是,我使用了一个通知模板的窗口,有一些动画效果。但是我没有看到它和其他的有什么大的区别。以下是XAML代码:WPF:按钮宽度不能更改得更小,wpf,windows,xaml,button,width,Wpf,Windows,Xaml,Button,Width,在我的WPF应用程序的一个窗口中,无论我做什么,都不能将按钮宽度更改为更小的大小。我尝试在xaml中更改“width”的属性,在designer中拖动按钮,或者使用c#实用地更改它。即使我在该窗口中创建了一个新按钮,宽度也只能更改为较大的尺寸,但不能更改为较小的尺寸。虽然没有错误或警告,但没有一种方法成功地更改宽度。奇怪的是,我可以通过拖动轻松地将按钮的高度更改为更小或更大,而在我的另一个窗口中,我可以轻松地将按钮的宽度和高度更改为更小或更大。我对所有窗口中的所有按钮使用相同的样式。如果我拖动按
<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>
你有什么想法吗?提前谢谢
你有什么想法吗
您忘记发布您显然正在使用的自定义样式的标记,但您可以尝试将按钮的MinWidth属性设置为0:
<Button x:Name="button1" Content="OK" Margin="358,341,13,72" Click="Submit_Click" FontSize="16"
VerticalAlignment="Top" HorizontalAlignment="Left" MinWidth="0"/>
如果仍然无法增加按钮的宽度,请发布XAML标记和代码的所有相关部分
你有什么想法吗
您忘记发布您显然正在使用的自定义样式的标记,但您可以尝试将按钮的MinWidth属性设置为0:
<Button x:Name="button1" Content="OK" Margin="358,341,13,72" Click="Submit_Click" FontSize="16"
VerticalAlignment="Top" HorizontalAlignment="Left" MinWidth="0"/>
如果仍然无法增加按钮的宽度,请发布XAML标记和代码的所有相关部分。是,这很有帮助!!非常感谢你!是的,这很有帮助!!非常感谢你!