ControlTemplate Button

时间:2016-03-22 10:07:35

标签: c# wpf xaml wpf-style

我现在遇到WPF / Xaml样式的问题:

我尝试创建一个可以显示文字或路径图标的通用按钮。当按钮悬停时,路径应该改变它的" Fill" -Property。

我当前的方法允许使用控件模板资源来为路径添加颜色样式,但是当鼠标移动按钮时我无法更改它。当前样式代码如下所示:

<Style TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border
                    x:Name="Border"
                    Background="{TemplateBinding Background}"
                    BorderThickness="0"
                    Padding="2">
                    <ContentPresenter
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            Margin="{TemplateBinding Padding}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            RecognizesAccessKey="True" />
                </Border>
                <ControlTemplate.Resources>
                    <Style TargetType="{x:Type Path}" BasedOn="{StaticResource {x:Type Path}}">
                        <Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}" />
                    </Style>
                </ControlTemplate.Resources>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">

                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="{StaticResource HoveredDarkBackgroundBrush}"/>
                        <Setter Property="Foreground" Value="#d0d0d0" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">

                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Background" Value="{StaticResource DarkBackgroundBrush}" />
    <Setter Property="Foreground" Value="#c4c4c4" />
</Style>

我知道我需要更改控件模板触发器中的颜色,但我不了解如何将颜色应用到路径中。 有人可以给我一些提示或解决方案的途径吗?

此致 菲利克斯

PS .: 样式按钮如下所示:

<Button ToolTip="...">
    <Path Data="..." />
</Button>

0 个答案:

没有答案
相关问题