【问题标题】:Why can I not access some properties on WPF controls?为什么我无法访问 WPF 控件上的某些属性?
【发布时间】:2012-02-28 02:55:28
【问题描述】:

我正在尝试将样式应用于 WPF 中的控件。并且注意到某些在代码隐藏中可用的属性在 XAML 中不可用?

这是为什么?

你能帮我举个例子吗:

<Style TargetType="RichTextBox">
        <Setter Property="VerticalScrollBarVisibility" Value="Auto"></Setter>
        <Setter Property="Background" Value="WhiteSmoke"></Setter>
        <Setter Property="Foreground" Value="#515151"></Setter>
        <Setter Property="Document.PageWidth" Value="300"></Setter>
    </Style>

当尝试将 PageWidth 应用到控件的 Document 时,我得到一个异常,它不可访问?

谢谢。

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    Setter.Property 不是路径,你不能用它来设置“properties of properties”。

    【讨论】:

    • 你能用文章或例子解释更多吗?抱歉不知道wpf。
    • @shenku:在相关的question of mine 中,大部分内容都应该被覆盖。另请阅读docs
    【解决方案2】:

    您可以单独为依赖属性设置样式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-30
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 2021-08-18
      • 2016-11-08
      相关资源
      最近更新 更多