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.

Conditional XAML not working in ResourceDictionaries

See original GitHub issue

Describe the bug Been having trouble trying to add more complex conditional XAML to our Resource Dictionaries (like just copying resources from the WinUI repo here that is using the same syntax is failing in our C# UWP Class Library).

The latest message I’ve received is Type 'TemplateBinding' used after '{' must be a Markup Extension. Error code 0x09cc. which seems similar to this old thread here.

Steps to reproduce the bug

  1. Clone WCT repo
  2. Open a ResourceDictionary for a control like (TokenizingTextbox.AutoSuggestBox.xaml)
  3. Paste in a system style for AutoSuggestBox (grabbed from Generic.xaml from 18362 for instance)
  4. Use VS Quick-Fix tip to apply conditional XAML for Description property.
  5. Try and compile. This should be valid XAML, but it fails.

I noticed this as well when trying to apply CornerRadius conditionally as well.

Expected behavior Compile and run.

Screenshots image

Version Info Class Library Min: 16299, Target 17763

Windows 10 version Saw the problem?
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT

VS 2019 16.5.5

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
michael-hawkercommented, Jun 7, 2022

Hitting this again with the Expander setter:

https://github.com/microsoft/microsoft-ui-xaml/blob/f132a034af64f83c65a2a20590c39399558905a4/dev/Expander/Expander.xaml#L6-L24

1>  Target MarkupCompilePass1:
1>    (Out) GeneratedCodeFiles: 'H:\code\Labs-UWP\labs\Expander\src\obj\Debug\uap10.0.17763\XamlTypeInfo.g.cs'
1>    (Out) GeneratedXamlFiles: 'H:\code\Labs-UWP\labs\Expander\src\obj\Debug\uap10.0.17763\Expander.xaml;H:\code\Labs-UWP\labs\Expander\src\obj\Debug\uap10.0.17763\Themes\Generic.xaml'
1>    (Out) GeneratedXbfFiles: 'H:\code\Labs-UWP\labs\Expander\src\obj\Debug\uap10.0.17763\Expander.xbf;H:\code\Labs-UWP\labs\Expander\src\obj\Debug\uap10.0.17763\Themes\Generic.xbf'
1>    (Out) Compile: 'AdditionalAssemblyInfo.cs;Expander.cs;H:\code\Labs-UWP\labs\Expander\src\obj\Debug\uap10.0.17763\XamlTypeInfo.g.cs'
1>  Target XamlPreCompile:
1>    CompilerServer: server - server processed compilation - aaa7992b-2225-4d8b-945c-a49f1c28c039
1>  Target MarkupCompilePass2:
1>    Expander.xaml(23,62): XamlCompiler error WMC0610: The XAML Binary Format (XBF) generator reported syntax error '0x03e9'
1>  Done building target "MarkupCompilePass2" in project "CommunityToolkit.Labs.WinUI.Expander.csproj" -- FAILED.
1>
1>  Done building project "CommunityToolkit.Labs.WinUI.Expander.csproj" -- FAILED.
1>  Target MarkupCompilePass1:
1>    (Out) GeneratedCodeFiles: 'H:\code\Labs-UWP\labs\Expander\src\obj\Debug\net6.0-windows10.0.19041.0\XamlTypeInfo.g.cs'
1>    (Out) GeneratedXamlFiles: 'H:\code\Labs-UWP\labs\Expander\src\obj\Debug\net6.0-windows10.0.19041.0\Expander.xaml;H:\code\Labs-UWP\labs\Expander\src\obj\Debug\net6.0-windows10.0.19041.0\Themes\Generic.xaml'
1>    (Out) GeneratedXbfFiles: 'H:\code\Labs-UWP\labs\Expander\src\obj\Debug\net6.0-windows10.0.19041.0\Expander.xbf;H:\code\Labs-UWP\labs\Expander\src\obj\Debug\net6.0-windows10.0.19041.0\Themes\Generic.xbf'
1>    (Out) Compile: 'AdditionalAssemblyInfo.cs;Expander.cs;H:\code\Labs-UWP\labs\Expander\src\obj\Debug\net6.0-windows10.0.19041.0\XamlTypeInfo.g.cs'
1>  Target XamlPreCompile:
1>    CompilerServer: server - server processed compilation - c836179b-62cb-4002-9de1-19f45a2f9efd
1>  Target MarkupCompilePass2:
1>    Expander.xaml(23,62): XamlCompiler error WMC0610: The XAML Binary Format (XBF) generator reported syntax error '0x03e9'

Looks like it is coming from both our UWP and WinAppSDK passes. The error message is also less helpful now than it was before.

I just copied the style into a new C# class library (in our Toolkit Labs) as I’m trying to investigate inheriting from the WinUI Expander for the Toolkit for 8.0. (Though since our min target is 17763, I think I can remove these checks, but still very confused why this is working in some places but not others still.)

1reaction
huynhsontungcommented, Dec 21, 2020

This problem persists even when targeting 19041 (min 17134). image

It only affects Setters in my case. I use contract7Present:CornerRadius and contract7Present:Description in other places in this file and it compiles just fine.

VS 2019 16.8.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to conditionally include XAML ResourceDictionary in ...
1 Answer 1 ... The error is caused by the path of Colors.xaml . ... Update: It's also valid to place all resources...
Read more >
Conditional XAML does not work with Setters
It seems there is a problem with XAML compiler that prevents conditional XAML from working with Style Setters in Resource dictionaries.
Read more >
ResourceDictionary Class (Windows.UI.Xaml) - UWP
Defines a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve...
Read more >
Untitled
WebAug 12, 2020 · To use a Xaml ResourceDictionary without a partial class (code behind class) (as indicated by the x:Class attribute), remove...
Read more >
Managing Application Resources when WPF is Hosted
Dear Dr. WPF,. We are running into some issues around application level resources when we attempt to put WPF task pane UI within...
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