我正在尝试创建一个简单的按钮模板,其中按钮通常看起来像一条水平线,但当鼠标悬停时,按钮将在其后面显示"矩形"颜色填充.这是我的代码,但我似乎无法触发触发器.
<Window x:Class="TestStylingWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="36" GlassFrameThickness="0 0 0 1" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Height="36" Width="36"
HorizontalAlignment="Center" VerticalAlignment="Center"
Grid.Row="0">
<Button.Template>
<ControlTemplate>
<Grid>
<Rectangle x:Name="PART_ButtonBackgroundRectangle" Fill="LightGray" Width="36" Height="36" Opacity="0" />
<Path x:Name="PART_ButtonPath" Data="M10,26 L26,26" Stroke="DarkGray" StrokeThickness="1.5" />
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="PART_ButtonBackgroundRectangle" Property="IsMouseOver" Value="True">
<Setter TargetName="PART_ButtonBackgroundRectangle" Property="Opacity" Value="1" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么我的触发器不起作用,或者更好的方法来做到这一点?我是WPF的新手,并想重构它(以便在许多按钮中使用它),但我不确定如何.
更新:好的,所以我想这似乎是因为按钮位于窗口的标题栏内.这有什么好办法吗?也许是一种设置按钮的点击/悬停优先级的方法?
Ert*_*maa 17
您需要设置Hittest可见的按钮,例如:
shell:WindowChrome.IsHitTestVisibleInChrome="True"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5463 次 |
| 最近记录: |