元々私はトリガーでTextDecorationのペンの色を変更しようとしましたが、ペンのx:Nameプロパティを設定するとターゲットが見つからないというエラーが発生しました。トリガーエラーでTextDecorationを設定する
<ControlTemplate x:Key="TabButton" TargetType="{x:Type Button}">
<Border x:Name="border" Padding="10,5" CornerRadius="5,5,0,0" Background="#62A9FF">
<TextBlock x:Name="text" Text="{TemplateBinding Content}"
Cursor="Hand" Foreground="#F9FCFF">
<TextBlock.TextDecorations>
<TextDecoration Location="Underline"
PenThicknessUnit="FontRecommended">
<TextDecoration.Pen>
<Pen Brush="White" Thickness="1">
<Pen.DashStyle>
<DashStyle Dashes="5"/>
</Pen.DashStyle>
</Pen>
</TextDecoration.Pen>
</TextDecoration>
</TextBlock.TextDecorations>
</TextBlock>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="local:MainWindow.TabActive" Value="False">
<Setter TargetName="border" Property="Background" Value="Transparent"/>
<Setter TargetName="text" Property="Foreground" Value="Black"/>
<Setter TargetName="text" Property="TextDecorations">
<Setter.Value>
<TextDecorationCollection>
<TextDecoration Location="Underline">
<TextDecoration.Pen>
<Pen Brush="Gray" Thickness="1">
<Pen.DashStyle>
<DashStyle Dashes="5"/>
</Pen.DashStyle>
</Pen>
</TextDecoration.Pen>
</TextDecoration>
</TextDecorationCollection>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
これでアプリケーションはエラーなしでビルドしますが、私はそれを実行すると、私はエラーを取得:
Cannot add content of type 'System.Windows.TextDecoration' to an object of type System.Windows.TextDecorationCollection
間違っていますか?あるいは別の方法があるかもしれませんか?
ありがとうございます!初期値throghスタイルを設定すると、実際に問題を解決するのに役立ちます – Alexander