BorderThicknessProperty被正确地应用,但是ForeGroundProperty没有。我试过交换setter的位置,以为可能只有第一个被应用。我试过其他几个属性,除了BorderThickness没有一个工作。我猜我需要到达Content的Textblock,但是我不知道我怎么做。
var foregroundSetter = new Setter()
{
Property = Button.ForegroundProperty,
Value = Brushes.LightGray
};
var borderThicknessSetter = new Setter()
{
Property = Button.BorderThicknessProperty,
Value = new Thickness(0)
};
var isEnabledTrigger = new Trigger()
{
Property = Button.IsEnabledProperty,
Value = false
//Setters = { foregroundSetter, borderThicknessSetter }
};
isEnabledTrigger.Setters.Add(foregroundSetter);
isEnabledTrigger.Setters.Add(borderThicknessSetter);
var style = new Style();
style.Triggers.Add(isEnabledTrigger);
var pdfButton = new Button()
{
Padding = new Thickness(0, 0, 0, 0),
Margin = new Thickness(0, 0, 5, 0),
Height = 18,
Width = 20,
Content = "PDF",
FontSize = 9,
FontWeight = FontWeights.SemiBold,
Foreground = Brushes.Red,
BorderBrush = Brushes.Transparent,
Background = Brushes.Transparent,
ToolTip = new ToolTip() { Content = "Create PDF of training day." },
Command = CreatePdfCommand,
CommandParameter = newTab,
Style = style
};
字符串
1条答案
按热度按时间rqenqsqc1#
您为Foreground属性(
Foreground = Brushes.Red
)分配了本地值。之后可能会触发样式触发器,但触发器中的Foreground setter将被忽略,因为本地值具有更大的权重(它被称为Dependency Property value precedence)要修复该行为,请通过样式设置器设置正常前景值:
字符串