Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional XAML not working in ResourceDictionaries #2556

Open
michael-hawker opened this issue May 27, 2020 · 10 comments
Open

Conditional XAML not working in ResourceDictionaries #2556

michael-hawker opened this issue May 27, 2020 · 10 comments
Labels
bug Something isn't working team-Markup Issue for the Markup team wct

Comments

@michael-hawker
Copy link
Collaborator

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

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label May 27, 2020
@MikeHillberg MikeHillberg added the team-Markup Issue for the Markup team label May 28, 2020
@robloo
Copy link
Contributor

robloo commented Jul 6, 2020

This is a really bad one to work around. I believe it's the same as reported by @MartinZikmund here:

https://developercommunity.visualstudio.com/content/problem/937077/conditional-xaml-does-not-work-with-setters.html

I haven't found a separate bug report.

@michael-hawker
Copy link
Collaborator Author

@ranjeshj @MikeHillberg can we get this triaged? It's really confusing why this is working in some cases and not others. Is there some other thing we should be doing here to get this to work?

@ranjeshj
Copy link
Contributor

ranjeshj commented Jul 7, 2020

@fabiant3 @stevenbrix can you take a look ?

@fabiant3 fabiant3 removed the needs-triage Issue needs to be triaged by the area owners label Jul 7, 2020
@fabiant3
Copy link
Member

fabiant3 commented Jul 7, 2020

Actually @evelynwu-msft might be in a better position to advise.

@evelynwu-msft
Copy link
Contributor

Hi @michael-hawker, would it be feasible for you to change the project's target platform version to 19041? This is one of several conditional XAML bugs known to exist prior to the 19041 SDK and there unfortunately isn't any workaround.

@michael-hawker
Copy link
Collaborator Author

michael-hawker commented Jul 10, 2020

@evelynwu-msft I think we're updating our target for our next milestone, we were still staying back on our minor release, so I'll test that out now that we can bump it. Thanks!

ghost pushed a commit to CommunityToolkit/WindowsCommunityToolkit that referenced this issue Nov 9, 2020
# Add ColorPickerButton to the Toolkit

Closes #3363 

## PR Type
What kind of change does this PR introduce?

Feature
Documentation content changes
Sample app changes

## What is the current behavior?

The toolkit, and WinUI/UWP, has no flyout ColorPicker. The color picker that currently exists is a large canvas-type control (that is incorrectly named). This existing control has lots of usability concerns discussed in #3363 and the WinUI repository.

## What is the new behavior?

A brand-new control is added to allow selecting and editing a color within a flyout. The selected color is always visible in the content area of a drop-down button as a preview. 

![example1](https://user-images.githubusercontent.com/17993847/87890618-4933cc00-ca05-11ea-8dca-0889f4d9f3c2.gif)

The new properties for this picker are below. Note that these are purposely name 'CustomPalette...' instead of 'Palette...' as multiple palettes may be supported in the future (windows colors, recent colors, custom palette all in different sections visible at the same time).

```csharp
/// <summary>
/// Gets the list of custom palette colors.
/// </summary>
public ObservableCollection<Windows.UI.Color> CustomPaletteColors { get; }

/// <summary>
/// Gets or sets the number of colors in each row (section) of the custom color palette.
/// A section is the number of columns within an entire row in the palette.
/// Within a standard palette, rows are shades and columns are unique colors.
/// </summary>
public int CustomPaletteColumns { get; set; }

/// <summary>
/// Gets or sets a custom IColorPalette .
/// This will automatically set <see cref="CustomPaletteColors"/> and <see cref="CustomPaletteSectionCount"/> 
/// overwriting any existing values.
/// </summary>
public IColorPalette CustomPalette { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the color palette is visible.
/// </summary>
public bool IsColorPaletteVisible { get; set; }
```

Making all of this easier is a new IColorPalette interface. Any class can implement this interface to provide a custom color palette such as windows colors (the default), RYB colors, Flat UI colors, etc. Colors could also be algorithmically generated.

```csharp
/// <summary>
/// Interface to define a color palette.
/// </summary>
public interface IColorPalette
{
    /// <summary>
    /// Gets the total number of colors in this palette.
    /// A color is not necessarily a single value and may be composed of several shades.
    /// </summary>
    int ColorCount { get; }

    /// <summary>
    /// Gets the total number of shades for each color in this palette.
    /// Shades are usually a variation of the color lightening or darkening it.
    /// </summary>
    int ShadeCount { get; }

    /// <summary>
    /// Gets a color in the palette by index.
    /// </summary>
    /// <param name="colorIndex">The index of the color in the palette.
    /// The index must be between zero and <see cref="ColorCount"/>.</param>
    /// <param name="shadeIndex">The index of the color shade in the palette.
    /// The index must be between zero and <see cref="ShadeCount"/>.</param>
    /// <returns>The color at the specified index or an exception.</returns>
    Color GetColor(int colorIndex, int shadeIndex);
}
```

## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [x] Sample in sample app has been added / updated (for bug fixes / features)
    - [x] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [x] Contains **NO** breaking changes

## Other information

**Control**

 * [x] Ensure the name ColorPickerButton is accepted
 * [x] Rename ColorPickerSlider to ColorPickerButtonSlider. ColorPickerSlider is already used by WinUI.
 * [x] Implement all accessibility functionality. Check tab ordering.
 * [x] This control originally used NumberBoxes for channel numerical input. Complete porting this functionality over to TextBoxes as the Toolkit does not have a dependency on WinUI.
 * [x] Support all visual state groups in the original ColorPicker. Connect all functionality
 * [x] Test changing all ColorPicker properties. Determine which ones make sense to ignore
 * [x] Trim displayed hex if alpha is not enabled
 * [x] ~~Switch to radio buttons to switch between RGB/HSV representation. A ComboBox within a Flyout is generally bad practice and is also limited by some bugs in UWP (#1467).~~
 * [x] Switch to ToggleButton instead of RadioButton for RGB/HSV representation. Radio buttons don't work in flyouts and controls well due to UWP bugs. ToggleButtons may also visually look better. The design follows a 'segmented control' concept discussed here: microsoft/microsoft-ui-xaml#2310
 * [x] Switch the default color palette to be the windows colors (if possible)
 * [x] Align formatting to the toolkit conventions
 * [x] Handle CornerRadius in the template. Conditional XAML? Check how other controls do this.
 * [x] Rename 'CustomPaletteSectionCount' to ~~'CustomPaletteWrapCount'~~ or 'CustomPaletteColumns' like UniformGrid
 * [x] Update selected palette color data template to provide correct contrast of the border with the selected color ~~to match with windows settings app (check mark overlay)~~ The check mark is not included as the size of swatches in the palette could be smaller than the check mark itself.
 * [x] Rename 'CustomPaletteColumns' to 'CustomPaletteColumnCount' 
 * [ ] Treat negative/zero numbers in CustomPaletteColumnCount as 'auto' and automatically calculate a good column count to keep rows/columns even. Set the default of this property to 0 'auto'.
 * [x] Improve spacing above/below channel sliders -- try 24px (2 x 12px)
 * [ ] Move localizable strings into resources
 * [x] ~Do not show the color (set the preview border visibility to collapsed) while the control is initializing. This prevents the default color from briefly appearing during initial load. Instead, the background will just show through.~
 * [x] Do not change the saturation and value in the hue slider background. Keep SV at maximum. This allows the hue to always be clear to the user and is in line with other implementations (like in Inkscape).
 * [x] Rename `WindowsColorPalette` to `FluentColorPalette`
 * [x] Show palette color display name in a tooltip
 * [x] Use the WinUI algorithm for light/dark color switching
 * [x] Each tab should have independent visibility using IsColorPaletteVisible (new), IsColorSpectrumVisible (existing) and IsColorChannelTextInputVisible (repurposed to mean the entire tab). The tabs still visible should take up available space remaining. With only one tab visible the tab header should disappear.

**Code Review**
 1. [x] The mini-palette and color preview will be all one color when the selected color is black or white. The calculated accent colors will not change and pressing them will not change the selected color. 
       * Requires feedback from Microsoft on how the accent colors are calculated in Windows
       * It is possible to specially handle when the color is as max/min value (black or white) at least the two accent colors to the left/right could be different shades of gray.
 1. [x] The mini-palette accent colors are destructive. Pressing back and forward by 1 will not restore the original color. 
       * Again, requires feedback from Microsoft on how the accent colors are calculated in Windows.
       * Due to perceptual adjustments it's likely this will always be destructive.
 1. [x] The third dimension slider in the spectrum tab will vary the other dimensions in the spectrum. This results in the spectrum cursor jumping around as the slider value changes. This might be related to HSV/RGB conversion but needs to be investigated.
 1. [x] Adjust the design of the sample app page to move the ColorPickerButton closer to the description.
 1. [x] Check if a ColorToDisplayName converter already exists. Consider adding control specific converters to their own sub-namespace.
 1. [x] The ColorPickerButton will derive from DropDownButton and have a ColorPicker property. Dependent on #3440 
 1. [x] The ColorPicker will have the same new style as the ColorPickerButton flyout. While it's a new concept to have tabs in a panel-type control, this is considered acceptable.
 1. [x] Merge @michael-hawker branch into this one when given the thumb's up. Both controls will be in the same directory.
 1. [x] Remove conditional XAML for corner radius after WinUI 3.0. Conditional XAML doesn't work correctly in resource dictionaries and with setters. See microsoft/microsoft-ui-xaml#2556, fixed with #3440
 1. [ ] All slider rendering will be broken out and put into a new ColorPickerSlider. This should simplify code-behind and the default template.
 1. [x] The Pivot tab width and show/hide of tabs will be controlled in code-behind. use of the pivot itself is somewhat dependent on issues with touch. The pivot, or switching to a new control, will not hold the release.
 1. [ ] Sliders should vary only 1-channel and keep the other channels at maximum. This ensures the gradient always makes sense and never becomes fully black/white/transparent. This could also be made a configuration of the ColorPickerSlider control. Edit: This does need to be configurable as it's only required in HSV mode.
 1. [ ] Add color history palette to the sample app

**Other**
 * [x] Complete integration with the sample app. Add XAML to dynamically change the control.
 * [ ] Complete documentation of the control

**Future**

These changes should be considered for future versions of the control. They are recorded here for lack of a better location.

 * [ ] The mini selected color palette may follow the Windows accent color lighter/darker shades algorithm. However, the implementation of this algorithm is currently unknown. This algorithm may be in the XAML fluent theme editor: https://github.com/microsoft/fluent-xaml-theme-editor
 * [ ] Switch back to NumberBox for all color channel numerical input. This will require WinUI 3.0 and the corresponding release of the toolkit. When microsoft/microsoft-ui-xaml#2757 is implemented, also use NumberBox for hex color input.
 * [ ] ~Remove the custom 'ColorPickerButtonSlider' after switch to WinUI 3.0. This assumes there is no additional control-specific code at that point. (It currently exists just to work-around UWP bugs).~ This should be turned into it's own full primitive control.
 * [ ] Update ColorSpectrum_GotFocus event handler (instructions are within code) after/if ColorSpectrum bugs are fixed (likely after WinUI 3.0
 * [ ] Use Color.IsEmpty if microsoft/microsoft-ui-xaml#2826 is implemented
 * [ ] ~Ensure PivotItems are properly removed once/if microsoft/microsoft-ui-xaml#2952 is closed.~
@huynhsontung
Copy link

huynhsontung commented 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

@HppZ
Copy link

HppZ commented May 20, 2021

This is a really bad one to work around. I believe it's the same as reported by @MartinZikmund here:

https://developercommunity.visualstudio.com/content/problem/937077/conditional-xaml-does-not-work-with-setters.html

I haven't found a separate bug report.

No fix yet?

huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Jun 22, 2021
huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Jun 26, 2021
huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Jul 17, 2021
huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Jul 20, 2021
huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Jul 27, 2021
huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Aug 4, 2021
huynhsontung added a commit to huynhsontung/WindowsCommunityToolkit that referenced this issue Aug 15, 2021
Sergio0694 pushed a commit to CommunityToolkit/dotnet that referenced this issue Oct 29, 2021
# Add ColorPickerButton to the Toolkit

Closes #3363 

## PR Type
What kind of change does this PR introduce?

Feature
Documentation content changes
Sample app changes

## What is the current behavior?

The toolkit, and WinUI/UWP, has no flyout ColorPicker. The color picker that currently exists is a large canvas-type control (that is incorrectly named). This existing control has lots of usability concerns discussed in #3363 and the WinUI repository.

## What is the new behavior?

A brand-new control is added to allow selecting and editing a color within a flyout. The selected color is always visible in the content area of a drop-down button as a preview. 

![example1](https://user-images.githubusercontent.com/17993847/87890618-4933cc00-ca05-11ea-8dca-0889f4d9f3c2.gif)

The new properties for this picker are below. Note that these are purposely name 'CustomPalette...' instead of 'Palette...' as multiple palettes may be supported in the future (windows colors, recent colors, custom palette all in different sections visible at the same time).

```csharp
/// <summary>
/// Gets the list of custom palette colors.
/// </summary>
public ObservableCollection<Windows.UI.Color> CustomPaletteColors { get; }

/// <summary>
/// Gets or sets the number of colors in each row (section) of the custom color palette.
/// A section is the number of columns within an entire row in the palette.
/// Within a standard palette, rows are shades and columns are unique colors.
/// </summary>
public int CustomPaletteColumns { get; set; }

/// <summary>
/// Gets or sets a custom IColorPalette .
/// This will automatically set <see cref="CustomPaletteColors"/> and <see cref="CustomPaletteSectionCount"/> 
/// overwriting any existing values.
/// </summary>
public IColorPalette CustomPalette { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the color palette is visible.
/// </summary>
public bool IsColorPaletteVisible { get; set; }
```

Making all of this easier is a new IColorPalette interface. Any class can implement this interface to provide a custom color palette such as windows colors (the default), RYB colors, Flat UI colors, etc. Colors could also be algorithmically generated.

```csharp
/// <summary>
/// Interface to define a color palette.
/// </summary>
public interface IColorPalette
{
    /// <summary>
    /// Gets the total number of colors in this palette.
    /// A color is not necessarily a single value and may be composed of several shades.
    /// </summary>
    int ColorCount { get; }

    /// <summary>
    /// Gets the total number of shades for each color in this palette.
    /// Shades are usually a variation of the color lightening or darkening it.
    /// </summary>
    int ShadeCount { get; }

    /// <summary>
    /// Gets a color in the palette by index.
    /// </summary>
    /// <param name="colorIndex">The index of the color in the palette.
    /// The index must be between zero and <see cref="ColorCount"/>.</param>
    /// <param name="shadeIndex">The index of the color shade in the palette.
    /// The index must be between zero and <see cref="ShadeCount"/>.</param>
    /// <returns>The color at the specified index or an exception.</returns>
    Color GetColor(int colorIndex, int shadeIndex);
}
```

## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [x] Sample in sample app has been added / updated (for bug fixes / features)
    - [x] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [x] Contains **NO** breaking changes

## Other information

**Control**

 * [x] Ensure the name ColorPickerButton is accepted
 * [x] Rename ColorPickerSlider to ColorPickerButtonSlider. ColorPickerSlider is already used by WinUI.
 * [x] Implement all accessibility functionality. Check tab ordering.
 * [x] This control originally used NumberBoxes for channel numerical input. Complete porting this functionality over to TextBoxes as the Toolkit does not have a dependency on WinUI.
 * [x] Support all visual state groups in the original ColorPicker. Connect all functionality
 * [x] Test changing all ColorPicker properties. Determine which ones make sense to ignore
 * [x] Trim displayed hex if alpha is not enabled
 * [x] ~~Switch to radio buttons to switch between RGB/HSV representation. A ComboBox within a Flyout is generally bad practice and is also limited by some bugs in UWP (#1467).~~
 * [x] Switch to ToggleButton instead of RadioButton for RGB/HSV representation. Radio buttons don't work in flyouts and controls well due to UWP bugs. ToggleButtons may also visually look better. The design follows a 'segmented control' concept discussed here: microsoft/microsoft-ui-xaml#2310
 * [x] Switch the default color palette to be the windows colors (if possible)
 * [x] Align formatting to the toolkit conventions
 * [x] Handle CornerRadius in the template. Conditional XAML? Check how other controls do this.
 * [x] Rename 'CustomPaletteSectionCount' to ~~'CustomPaletteWrapCount'~~ or 'CustomPaletteColumns' like UniformGrid
 * [x] Update selected palette color data template to provide correct contrast of the border with the selected color ~~to match with windows settings app (check mark overlay)~~ The check mark is not included as the size of swatches in the palette could be smaller than the check mark itself.
 * [x] Rename 'CustomPaletteColumns' to 'CustomPaletteColumnCount' 
 * [ ] Treat negative/zero numbers in CustomPaletteColumnCount as 'auto' and automatically calculate a good column count to keep rows/columns even. Set the default of this property to 0 'auto'.
 * [x] Improve spacing above/below channel sliders -- try 24px (2 x 12px)
 * [ ] Move localizable strings into resources
 * [x] ~Do not show the color (set the preview border visibility to collapsed) while the control is initializing. This prevents the default color from briefly appearing during initial load. Instead, the background will just show through.~
 * [x] Do not change the saturation and value in the hue slider background. Keep SV at maximum. This allows the hue to always be clear to the user and is in line with other implementations (like in Inkscape).
 * [x] Rename `WindowsColorPalette` to `FluentColorPalette`
 * [x] Show palette color display name in a tooltip
 * [x] Use the WinUI algorithm for light/dark color switching
 * [x] Each tab should have independent visibility using IsColorPaletteVisible (new), IsColorSpectrumVisible (existing) and IsColorChannelTextInputVisible (repurposed to mean the entire tab). The tabs still visible should take up available space remaining. With only one tab visible the tab header should disappear.

**Code Review**
 1. [x] The mini-palette and color preview will be all one color when the selected color is black or white. The calculated accent colors will not change and pressing them will not change the selected color. 
       * Requires feedback from Microsoft on how the accent colors are calculated in Windows
       * It is possible to specially handle when the color is as max/min value (black or white) at least the two accent colors to the left/right could be different shades of gray.
 1. [x] The mini-palette accent colors are destructive. Pressing back and forward by 1 will not restore the original color. 
       * Again, requires feedback from Microsoft on how the accent colors are calculated in Windows.
       * Due to perceptual adjustments it's likely this will always be destructive.
 1. [x] The third dimension slider in the spectrum tab will vary the other dimensions in the spectrum. This results in the spectrum cursor jumping around as the slider value changes. This might be related to HSV/RGB conversion but needs to be investigated.
 1. [x] Adjust the design of the sample app page to move the ColorPickerButton closer to the description.
 1. [x] Check if a ColorToDisplayName converter already exists. Consider adding control specific converters to their own sub-namespace.
 1. [x] The ColorPickerButton will derive from DropDownButton and have a ColorPicker property. Dependent on #3440 
 1. [x] The ColorPicker will have the same new style as the ColorPickerButton flyout. While it's a new concept to have tabs in a panel-type control, this is considered acceptable.
 1. [x] Merge @michael-hawker branch into this one when given the thumb's up. Both controls will be in the same directory.
 1. [x] Remove conditional XAML for corner radius after WinUI 3.0. Conditional XAML doesn't work correctly in resource dictionaries and with setters. See microsoft/microsoft-ui-xaml#2556, fixed with #3440
 1. [ ] All slider rendering will be broken out and put into a new ColorPickerSlider. This should simplify code-behind and the default template.
 1. [x] The Pivot tab width and show/hide of tabs will be controlled in code-behind. use of the pivot itself is somewhat dependent on issues with touch. The pivot, or switching to a new control, will not hold the release.
 1. [ ] Sliders should vary only 1-channel and keep the other channels at maximum. This ensures the gradient always makes sense and never becomes fully black/white/transparent. This could also be made a configuration of the ColorPickerSlider control. Edit: This does need to be configurable as it's only required in HSV mode.
 1. [ ] Add color history palette to the sample app

**Other**
 * [x] Complete integration with the sample app. Add XAML to dynamically change the control.
 * [ ] Complete documentation of the control

**Future**

These changes should be considered for future versions of the control. They are recorded here for lack of a better location.

 * [ ] The mini selected color palette may follow the Windows accent color lighter/darker shades algorithm. However, the implementation of this algorithm is currently unknown. This algorithm may be in the XAML fluent theme editor: https://github.com/microsoft/fluent-xaml-theme-editor
 * [ ] Switch back to NumberBox for all color channel numerical input. This will require WinUI 3.0 and the corresponding release of the toolkit. When microsoft/microsoft-ui-xaml#2757 is implemented, also use NumberBox for hex color input.
 * [ ] ~Remove the custom 'ColorPickerButtonSlider' after switch to WinUI 3.0. This assumes there is no additional control-specific code at that point. (It currently exists just to work-around UWP bugs).~ This should be turned into it's own full primitive control.
 * [ ] Update ColorSpectrum_GotFocus event handler (instructions are within code) after/if ColorSpectrum bugs are fixed (likely after WinUI 3.0
 * [ ] Use Color.IsEmpty if microsoft/microsoft-ui-xaml#2826 is implemented
 * [ ] ~Ensure PivotItems are properly removed once/if microsoft/microsoft-ui-xaml#2952 is closed.~
@michael-hawker
Copy link
Collaborator Author

michael-hawker commented Jun 7, 2022

Hitting this again with the Expander setter:

xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)">
<Style TargetType="local:Expander" BasedOn="{StaticResource DefaultExpanderStyle}"/>
<Style x:Key="DefaultExpanderStyle" TargetType="local:Expander">
<!-- We won't make this control tab stoppable, since the tab focus should go
to the toggle button. For this logic, several things were made:
1. Expander::OnApplyTemplate - We set the toggle button's events source to the expander's. This will announce expander properties
(expand/collapse) changes to narrator. Without this, narrator would announce the toggle button's "on/off" logic
instead of the "expand/collapse" logic.
2. ExpanderAutomationPeer::GetChildrenCore - Because of 1., we need to override GetChildrenCore to NOT include the toggle button.
If we don't do this, we create a weird dependency cycle between the toggle button and the expander.
3. ExpanderAutomationPeer::GetPeerFromPointCore Finally, when using narrator with a touch screen, this was overriden as well, to
focus the toggle button programmatically to sync the narrator focus with the keyboard focus.
Without this override, the narrator user that focuses the expander on a touch screen will see that pressing "Tab"
doesn't work how they would expect.-->
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Background" Value="{ThemeResource ExpanderContentBackground}" />
<contract7Present:Setter Property="BackgroundSizing" Value="InnerBorderEdge" />

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

michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue Jun 8, 2022
Added workaround for DefaultStyleResourceUri - see microsoft/microsoft-ui-xaml#3502
Removed contract7Present from Style (our min target anyway) - see microsoft/microsoft-ui-xaml#2556
Tested on UWP, WinUI 3, and WASM!
michael-hawker added a commit to CommunityToolkit/Labs-Windows that referenced this issue Jul 8, 2022
Added workaround for DefaultStyleResourceUri - see microsoft/microsoft-ui-xaml#3502
Removed contract7Present from Style (our min target anyway) - see microsoft/microsoft-ui-xaml#2556
Tested on UWP, WinUI 3, and WASM!
@evelynwu-msft
Copy link
Contributor

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

@huynhsontung @michael-hawker Currently conditional XAML is not supported on the entire Style Setter, only on Setter.Value or within the object being assigned to Setter.Value.

@duncanmacmichael duncanmacmichael added the bug Something isn't working label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working team-Markup Issue for the Markup team wct
Projects
None yet
Development

No branches or pull requests

10 participants