我正在动态制作按钮,因此我在资源中拥有一种风格,我需要能够具有最大宽度,但是当达到最大宽度时,它会向下调整大小。我该怎么办?
<Style x:Key="TaskButton" TargetType="{x:Type Button}" BasedOn="{StaticResource BaseStyle}">
<Setter Property="Background" Value="{StaticResource BackgroundVeryLightBrush}" />
<Setter Property="Foreground" Value="{StaticResource ForegroundVeryDarkBrush}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FontSize" Value="{StaticResource FontSizeSmall}" />
<Setter Property="FontFamily" Value="{StaticResource LatoRegular}" />
<Setter Property="Padding" Value="5 5" />
<Setter Property="Margin" Value="5 5" />
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="MinWidth" Value="180" />
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ButtonBase}">
<Border x:Name="border"
CornerRadius="5"
BorderBrush="Transparent"
BorderThickness="1"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<TextBlock Text="{TemplateBinding Content}"
Focusable="False"
FontFamily="{TemplateBinding FontFamily}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="border" Value="{StaticResource WordBlueBrush}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="border" Value="{StaticResource ForegroundDarkBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>