有沒有一種簡單的方法來獲取Windows 10/Windows 11強調色XAML?
我看了很多例子,但大多數都不起作用。我也看到一些例子,模仿顏色改變行為C#,但他們沒有作業Windows 11。
我的代碼:
<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}"
Color="{x:Static SystemParameters.WindowGlassBrush}"/>
我只想Color將 Windows 當前的強調色設定為。
謝謝你。
uj5u.com熱心網友回復:
您應該能夠使用UISettings.GetColorValueWinRT API檢索強調色。
根據您的目標是 .NET 5 還是更早版本,您應該將 設定TargetFramework為net5.0-windows10.0。* 或Microsoft.Windows.SDK.Contracts按照此處所述安裝NuGet 包。
然后,您可以SolidColorBrush使用 API 的回傳值創建一個:
var color = new Windows.UI.ViewManagement.UISettings()
.GetColorValue(UIColorType.Accent);
var brush = new SolidColorBrush
(Color.FromArgb(color.A, color.R, color.G, color.B));
uj5u.com熱心網友回復:
什么起作用Windows 10,也起作用Windows 11。
作業系統: Windows 11 Build 10.0.22000.282
對比: 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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/349416.html
