Mapplesoft
Mapplesoft

Reputation: 297

Conditional XAML Crashes UWP App

My UWP app targets a min version of 1703 and a max of 1803. It also uses an AcrylicBrush, which wasn't available until 1709. I'm trying to use conditional XAML to create an AcrylicBrush when the current version supports it (i.e. version is 1709 or higher).

Below I have a rectangle with the fill defined twice, once for anything before 1709, and once for 1709 and later. This code works.

Edit:

The code below should be Version1803 and Not1803. The answer from Rafael is right; Windows 10 Mobile 1709 will crash with this... but 1703 should not.... So for the sake of simplicity, just replace "1709" with "1803". With that said, does anyone know why it is crashing on 1703?

--end of edit.

xmlns:Version1709="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:Not1709="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"

<Rectangle x:Name="AcrylicRectangle">
     <Version1709:Rectangle.Fill>
           <AcrylicBrush Opacity="0.5"></AcrylicBrush> 
    </Version1709:Rectangle.Fill>
    <Not1709:Rectangle.Fill>
          <SolidColorBrush Color="Red" Opacity="0.5"></SolidColorBrush>
    </Not1709:Rectangle.Fill>
 </Rectangle>

Here's the scoop: 1709 and newer have a transparent rectangle (because no color is set) and older than 1709 has a red rectangle, so far so good. This is where the problems start. You'll notice the only attribute I defined in AcrylicBrush is Opacity; any other defined attribute, like TintColor, TintOpacity, etc. will crash the app on 1703 Mobile. I've tried many different variations but they all have the same problem:

<AcrylicBrush Version1709:TintColor="Red" Opacity="0.5"></AcrylicBrush>
<AcrylicBrush TintColor="Red" Opacity="0.5"></AcrylicBrush>
<Version1709:AcrylicBrush Version1709:TintColor="Red" Opacity="0.5"></Version1709:AcrylicBrush>
<Version1709:AcrylicBrush TintColor="Red" Opacity="0.5"></Version1709:AcrylicBrush>

From the four AcrylicBrushes above I get this error at runtime on 1703 on Mobile:

Activation of the Windows Store app 'a77e7506-7031-4935-ad70-ef56585020de_h83rr06hb5xc0!App' failed with error 'Windows was unable to communicate with the target application. This usually indicates that the target application's process aborted. More information may be available in the Debug pane of the Output window (Debug->Windows->Output)'. The program '[6928] [UWPAppName].exe' has exited with code -1073741189 (0xc000027b).

What am I doing wrong?

EDIT When I say versions before 1709, that entails only 1703, since that is the minimum target. Conditional XAML isn't supported in versions earlier than 1703 (Build 15063) so this is not the issue.

Upvotes: 4

Views: 396

Answers (1)

MrCSharp
MrCSharp

Reputation: 1143

AcrylicBrush is not supported on Windows 10 Mobile's latest build. The documentation (https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.acrylicbrush) specifies that AcrylicBrush is only available on Fall Creators Update 10.0.16299 which was never available for Mobile (latest version available is 10.0.15254.490).

I think the problem here is that AcrylicBrush is not avilable on the latest Mobile build.

Best option for you here is to create a class inheriting from FrameworkElement with the Attached DependencyProperties for the properties you need. Do the Contract level check in that class and update the background property with the appropriate brush based on that level.

Upvotes: 1

Related Questions