0
我想在MouseOver上将按钮的BorderThickness属性设置为5,除非BorderThickness增加了填充内容的按钮内容,这是我不希望发生的事情。有没有办法绕过/禁用此?WPF BorderThickness禁用子元素填充
这里是我的代码
<ControlTemplate TargetType="{x:Type Button}">
<ControlTemplate.Resources>
<Storyboard x:Key="MouseOverAnimation">
<ThicknessAnimation Storyboard.TargetName="ButtonBorder" Storyboard.TargetProperty="BorderThickness" To="3" Duration="0:0:0.2" />
</Storyboard>
<Storyboard x:Key="MouseOutAnimation">
<ThicknessAnimation Storyboard.TargetName="ButtonBorder" Storyboard.TargetProperty="BorderThickness" To="1" Duration="0:0:0.2" />
</Storyboard>
</ControlTemplate.Resources>
<Border x:Name="ButtonBorder" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
<VirtualizingStackPanel VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" Background="{TemplateBinding Background}">
<ContentPresenter Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"/>
</VirtualizingStackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource MouseOverAnimation}"></BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
这里是在XAML
<Button Style="{StaticResource SoulsButton}" Width="150" >
<TextBlock FontFamily="Resources/Fonts/#Univers UltraCondensed" FontSize="20" Foreground="{StaticResource DarkSoulsYellow}" Width="50" Height="20">INSTALL</TextBlock>
</Button>
试试这个,摆脱宽度= 150,并把它放在一个容器中的150宽度代替,然后更改按钮STRECH的horizonatalalignment。 –
Nope不起作用,整个按钮现在成为jello – johns193
使容器按钮包含在Grid中。 –