如何在 xaml 中获取样式 setter 属性的值?
例如,我有下一个风格:
<Style TargetType="TextBox">
<Setter Property="Background" Value="YellowGreen" />
</Style>
如何从 TextBox 默认样式中获取 Background 属性的值?
<Style TargetType="Button">
<Setter Property="Background" Value="{Binding ???}" />
</Style>
我需要这个,因为 我无法访问
TextBox
款式 ..
最佳答案
如果您无法修改 TextBox 样式,则可以解决此问题(经过测试,有效):
<TextBox x:Key="DefaultTextBox" />
<Style TargetType="Button">
<Setter Property="Background"
Value="{Binding Source={StaticResource DefaultTextBox}, Path=Background}" />
</Style>
您不能在 xaml 中绑定(bind)到样式的背景 setter 。
关于wpf - 从 xaml 中的样式 setter 属性获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16812605/