question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Can I declare a conditional XAML static resource?

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
evelynwu-msftcommented, Jul 11, 2020

@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.

1reaction
robloocommented, Jul 10, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional Resources Creation WPF XAML Design / Run ...
Finally my question is : How can I conditionnaly let Resources be created in "low level" control ( so that I can have...
Read more >
Conditional XAML - UWP applications
It selectively parses elements or attributes to determine whether they will be available at runtime. Conditional statements are evaluated at ...
Read more >
Overview of XAML resources (WPF .NET)
Static resource references always load from XAML when the page loads. However, a dynamic resource reference doesn't load until it's used. You're ...
Read more >
Intellisense help choosing SolidColorBrush name for a ...
Intellisense help choosing SolidColorBrush name for a Button in WPF XAML omits the "." seperator between StaticResource and custom key for SolidColorBClosed ...
Read more >
DXimage in Static Resource without hard-coding ...
I would like to define a devexpress image in a resource so that it can be referenced in multiple places via StaticResource.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found