Ant*_*ony 5 wpf label styles hyperlink
鉴于以下 XAML 标记,当我将鼠标悬停在超链接上时,我希望超链接中的文本变为橙色,因为我在其父控件上设置前景色,并且它应该通过Property Value Inheritance进行过滤。但它仍然是黑色的。我需要做什么?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="DemoLink" TargetType="{x:Type Hyperlink}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="DarkOrange" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Label>
<Hyperlink Style="{StaticResource DemoLink}">
<Label Content="Text that should change colour on mouse over" />
</Hyperlink>
</Label>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
例如
<Label>
<Hyperlink Style="{StaticResource DemoLink}">
<TextBlock Text="Text that does change colour on mouse over" />
</Hyperlink>
</Label>
Run Code Online (Sandbox Code Playgroud)
似乎Label不受Foreground其父级设置的影响。即使这样也没有效果
<Label>
<Hyperlink Style="{StaticResource DemoLink}" Foreground="DarkOrange">
<Label Content="This is some text that should change colour on mouse over" />
</Hyperlink>
</Label>
Run Code Online (Sandbox Code Playgroud)
更新
为 the 设置样式Label而不是 the Hyperlink,它会起作用
<Window.Resources>
<Style x:Key="DemoLinkLabel" TargetType="Label">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="DarkOrange" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Label>
<Hyperlink Name="DemoHyperlink" >
<Label Content="This is some text that should change colour on mouse over"
Style="{StaticResource DemoLinkLabel}"/>
</Hyperlink>
</Label>
</Grid>
Run Code Online (Sandbox Code Playgroud)
再次更新
最简单的方法是使用 aTextBlock代替,Label因为它没有这个问题
<Hyperlink Name="DemoHyperlink" Style="{StaticResource DemoLink}">
<TextBlock Text="This is some text that should change colour on mouse over"/>
</Hyperlink>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7380 次 |
| 最近记录: |