wpf - 从 xaml 中的样式 setter 属性获取值

标签 wpf

如何在 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/

相关文章:

WPF DataGrid - 刷新后保持滚动位置

c# - 如何使用 MVVM 模式在 WPF 数据网格中绑定(bind) CurrentCell

c# - Entity Framework 6 不在 SQLite 数据库中创建表

c# - 动画列表框中的已删除项目

wpf - 通过 MVP 中的继承来改变 Presenter

c# - 将 TextBox 中的值传递给 ValidationRule

wpf - 与 ContextMenu 中的 HierarchicalDataTemplate 作斗争

c# - WPF 数据访问层体系结构

wpf - 数据模板的复用

c# - 带有 C# WPF 的 EMGU