c# - UWP AcrylicBrush 向后兼容最低版本 14393(周年更新)

标签 c# .net xaml uwp backwards-compatibility

我正在开发我的 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/

相关文章:

wpf - 30 行 WPF 应用程序泄漏内存

c# - 在 RavenDB 中存储具有 Func<T, TResult> 成员的类

c# - 在 UWP 应用程序中制作向导的正确方法?

c# - 如何让 byte[] 显示为 View 上 div 的背景图像(C#、ASP.NET、MVC)

c# - 如何将 WPF 控件文本绑定(bind)到 bool 值,并在 xaml 中决定文本

.net - 服务启动时的 DLL 加载顺序

c# - RavenDb - 按结果过滤分组的多图索引

c# - 在组合框中的绑定(bind)项目上使用转换器

.net - 将 JSON 解析为 .NET 4.0 中的非对象?

c# - DataBind到ObservableCollection,只显示某个派生类的元素