Я пытаюсь создать шаблон кнопки, который меняет свои цвета при нажатии.
К сожалению, я не могу заставить его работать.
Я использую BorderBrush как временную переменную,Скорее всего, существуют более сложные решения.
Вот мой код.
<Style TargetType="{x:Type Button}">
<Style.Setters>
<Setter Property="Foreground"
Value="{StaticResource RahmenFarbe}" />
<Setter Property="Background"
Value="{StaticResource HintergrundFarbe}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
ClipToBounds="True">
<Border BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Foreground}"
x:Name="ButtonBorder"
CornerRadius="25"
BorderThickness="4"
Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Background}"
RenderTransformOrigin="0.5,0.5">
<TextBlock x:Name="ButtonTextBlock"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Foreground}"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<ContentPresenter x:Name="myContentPresenter"
Content="{TemplateBinding Content}" />
</TextBlock>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed"
Value="True">
<Setter Property="BorderBrush"
Value="{Binding Mode=OneTime, Path=Foreground}" />
<Setter Property="Foreground"
Value="{Binding Mode=OneTime, Path=Background}" />
<Setter Property="Background"
Value="{Binding Mode=OneTime, Path=BorderBrush}" />
</Trigger>
</ControlTemplate.Triggers >
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
Буду признателен за любую помощь.
С уважением, Себастьян