我正在开发我的 UWP 应用。我设置的是:
- 目标版本:16299
- 最低版本:14393
我使用一些 AcrylicBrushes。因为他们需要16299版本,所以我有两个带画笔的文件:
- Styles/Brushes.xaml(低于 16299 - 仅 SolidColorBrushes)
- Styles/Fall/Brushes.xaml(16299 及以上 - SolidColorBrushes 和 AcrylicBrushes)
我在 App.xaml.cs 中使用下面的代码
private void SetupStyles() {
var prefix = PlatformApiService.IsAcrylicBrushAvailable ? "Fall/" : string.Empty;
var brushUri = new Uri($"ms-appx:///Styles/{prefix}Brushes.xaml", UriKind.Absolute);
Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = brushUri });
}
当最小版本为 10586 时,一切正常,但使用 14393 时,我的应用程序无法构建,因为:
Type 'Windows.UI.Xaml.Media.AcrylicBrush' is defined under contract 'Windows.Foundation.UniversalApiContract' version '5.0.0.0', but the contract version for the targeted min version is '3.0.0.0'!
Member 'BackgroundSource' on type 'Windows.UI.Xaml.Media.IAcrylicBrush' is defined under contract 'Windows.Foundation.UniversalApiContract' version '5.0.0.0', but the contract version for the targeted min version is '3.0.0.0'!
Member 'FallbackColor' on type 'Windows.UI.Xaml.Media.IXamlCompositionBrushBase' is defined under contract 'Windows.Foundation.UniversalApiContract' version '4.0.0.0', but the contract version for the targeted min version is '3.0.0.0'!
我无法使用 Conditional XAML ,因为它需要15063版本。我该怎么办?
最佳答案
您可以在 XAML 中将资源设为 SolidColorBrushes,然后在 C# 中将其覆盖为 Acrylic 画笔
if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
{
var brush= ((SolidColorBrush)App.Current.Resources["ExampleBrush"]).Color;
App.Current.Resources["ExampleBrush"] = new AcrylicBrush()
{
TintOpacity = ,
TintColor = brush,
FallbackColor = brush,
BackgroundSource = AcrylicBackgroundSource.HostBackdrop
};
}
关于c# - UWP AcrylicBrush 向后兼容最低版本 14393(周年更新),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48476605/