是否有一种简单的方法在Windows 10 / Windows 11重音颜色中获得XAML
我看了很多例子,但大多数都不起作用。我还看到了一些模仿C#中颜色变化行为的示例,但它们在Windows 11中不起作用。
我的代码:
<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}"
Color="{x:Static SystemParameters.WindowGlassBrush}"/>我只想将Color设置为windows当前重音颜色。
谢谢。
发布于 2021-11-04 14:17:00
在Windows 10中起作用的东西,也在Windows 11中起作用。
OS:Windows 11 Build 10.0.22000.282
VS:2022 Preview 7.0
WPF:.NET 6
UserLabel.Background = SystemParameters.WindowGlassBrush;<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBase}"
x:Key="TextColored">
<Setter Property="FontWeight"
Value="SemiBold"/>
<Setter Property="Foreground"
Value="{x:Static SystemParameters.WindowGlassBrush}"/>
</Style>这在不添加任何NuGets的情况下有效。
发布于 2021-11-02 18:59:51
您应该能够使用UISettings.GetColorValue WinRT API检索重音颜色。
根据您的目标是.NET 5还是更早的版本,您应该将TargetFramework设置为net5.0-windows10.0.*,或者按照描述的这里安装Microsoft.Windows.SDK.Contracts NuGet包。
然后可以使用API的返回值创建SolidColorBrush:
var color = new Windows.UI.ViewManagement.UISettings()
.GetColorValue(UIColorType.Accent);
var brush = new SolidColorBrush
(Color.FromArgb(color.A, color.R, color.G, color.B));https://stackoverflow.com/questions/69814781
复制相似问题