我不知道是否有人能帮助,我设计一个自定义的WPF窗口的应用程序我的工作和我有一个最小值,最大值和关闭按钮的问题。我为3个按钮设计了一个ControlTemplate
,并且他们在Vertical
方向中的StackPanel
。在我的基本样式,我有以下问题与WPF风格
<Style x:Key="BaseWindowButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value={Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
<Setter Property="Background" Value="Transparent" />
...
</Style>
也试过前景色设置为特定的颜色,如#FF000000
并没有显示
我有一个继承了这种风格的按钮,但不会改变风格前景或背景。
我的问题是,按钮内容不显示,按钮显示和IsMouseOver
触发火灾改变背景,但文本内容永远不会显示。
闽按钮样式是
<Button x:Name="PART_Min">
<Path Fill="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"
Data="F1M0,6L0,9 9,9 9,6 0,6z"
SnapsToDevicePixels=True" />
</Button>
我很茫然,为什么内容不显示这样会感激你的看法。
可视树低于,我已经研究过这一点,并确定在前台值
Window (Foreground: #FF000000)
Grid
AdornerDecorator
Grid
ContentControl (Foreground: #FF000000)
StackPanel
Button (Foreground: #FF000000)
Grid
ContentControl (Foreground: #FF000000)
但是就像我上面说我已删除的绑定和指定的物理值,但仍没有得到显示
内容
绑定到“TextElement.Foreground”的解决方法是什么? – Gusdor
我是WPF的新手,所以这里我的理解是有限的,但是相对的源绑定将是类型为FrameworkElement的Button的基类型 –
'{RelativeSource AncestorType = {x:Type FrameworkElement}}'将使用a来自元素树中较高层的'FrameworkElement',而不是继承树。这可能是Button的父元素。使用Visual Studio的“Live Visual Tree”来查找绑定值的内容。 – Gusdor