Microsoft-ui-xaml: Question: Can I declare a conditional XAML static resource?

Created on 8 Jul 2020  路  9Comments  路  Source: microsoft/microsoft-ui-xaml


I have a app with conditional ThemeShadow, it works fine with 1903+ however on 1803 it crashes. It complaints that there is a XAML parsing error.

<MainPage
    x:Class="App.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:windows10Version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)"
    Style="{StaticResource PageStyle}"
    mc:Ignorable="d">
    <MainPage.Resources>
        <windows10Version1903:ThemeShadow x:Name="SharedShadow" />
    </MainPage.Resources>

Is there a workaround? Or am I doing something wrong?

area-Parser bug question team-Markup

Most helpful comment

@robloo As one of the maintainers of the XamlCompiler toolchain (specifically, the parser), I suspect I share many of your frustrations. At the moment we are focused entirely on shipping WinUI 3.0 (which, unfortunately, is not likely to fundamentally change how we process XAML markup) but modernizing the architecture of XamlCompiler is very much something we want to tackle in the future; we have several ideas about how to go about doing this but they do have to be balanced with other competing priorities.

All 9 comments

@harvinders Does the XAML parsing error sound like the one in https://github.com/microsoft/microsoft-ui-xaml/issues/2556? Or is a different error text?

Can you show the xaml where you reference this resource as well? Also can you copy the full error you are seeing into this issue as well?

@StephenLPeters Please find the repo at https://github.com/harvinders/ShadowTestApp

When run on the 1803 we get the error

Windows.UI.Xaml.Markup.XamlParseException
HResult=0x802B000A
Message=XAML parsing failed.

       at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
   at App1.MainPage.InitializeComponent() in C:\Users\mahimab\Downloads\ShadowTestApp-master\ShadowTestApp-master\App1\obj\x64\Debug\MainPage.g.i.cs:line 41
   at App1.MainPage..ctor() in C:\Users\mahimab\Downloads\ShadowTestApp-master\ShadowTestApp-master\App1\MainPage.xaml.cs:line 29

@alwu-msft FYI

@harvinders You're not doing anything wrong; this looks like a bug in how single-item ResourceDictionaries interact with conditional XAML.

As a workaround, could you try adding a second item into that ResourceDictionary? It doesn't have to be used anywhere; what's important is that the ResourceDictionary contains at least two items in it.

@alwu-msft the work around worked.

There are several issues related to conditional XAML, #2556 is definitely in the same category of issues.

@StephenLPeters
It's become clear over the years that the XAML compiler is kind-of a mess. Is there any work or plans towards re-writing this? I heard rumors that Xamarin.Forms, UWP and WPF could all share the same XAML infrastructure. Even trying to rename .xaml to .winui is a result of some bad architecture here.

@robloo As one of the maintainers of the XamlCompiler toolchain (specifically, the parser), I suspect I share many of your frustrations. At the moment we are focused entirely on shipping WinUI 3.0 (which, unfortunately, is not likely to fundamentally change how we process XAML markup) but modernizing the architecture of XamlCompiler is very much something we want to tackle in the future; we have several ideas about how to go about doing this but they do have to be balanced with other competing priorities.

@alwu-msft Thanks for your response. I understand we all have to prioritize our time. It's encouraging to hear this has been discussed internally and is something that might be tackled in the future.

Was this page helpful?
0 / 5 - 0 ratings