检索默认选择不透明度

Retrieve the Default Selection Opacity

WPF 中的文本选择(文本框等)看起来不同于其他 UI 工具包,因为 WPF 在其选择矩形的文本上使用半透明覆盖。

SystemColors class provides the color used for that rectangle in the HighlightColor property(以及与之相关的其他属性)。但是,该颜色是完全不透明的。因此,颜色必须用作降低的不透明度。

TextBoxBase.SelectionOpacity, PasswordBox.SelectionOpacity and on FlowDocumentPageViewer.SelectionOpacity 上的文档页面建议:

The default is 0.4.

另一方面,this blogpost 说:

SelectionOpacity (...) defaults to a value of .6.

无论默认值是什么,是否有任何方法可以从环境中检索要与 SystemColors.HighlightColor 一起使用的选择不透明度,而不是硬编码任意值(这甚至可能不是非标准高亮颜色的最佳选择)?

不,是的..没有SystemColors.HighlightOpacity - 但应该有。

SelectionOpacity 默认 属性 值是 硬编码 到 WPF 中的 0.4:http://referencesource.microsoft.com/#PresentationFramework/Framework/System/Windows/Controls/Primitives/TextBoxBase.cs,9716201433499854

我不太清楚这有什么不同(正如你所说的 0.6),它似乎在每个支持它的 .NET 中都被硬编码为 0.4(4.0、4.5)。

如果想真正查询SelectionOpacityProperty的默认值,可以这样做:

var prop = TextBoxBase.SelectionOpacityProperty;
var defValue = (double) prop.DefaultMetadata.DefaultValue; // 0.4