AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.22k stars 2.18k forks source link

11.2.0-beta1 - XAML compiler error when using binding in style setter #16754

Open pavelovcharov opened 3 weeks ago

pavelovcharov commented 3 weeks ago

Describe the bug

Using Avalonia v11.2.0-beta1 I get a compiler error AVLN1000 Avalonia: String '' was not recognized as a valid Boolean when using a binding as a style setter value.

This used to work in v11.1.3.

To Reproduce

Add style as shown below

        <Style Selector="Border.Test">
            <Setter Property="IsVisible">
                <Setter.Value>
                    <MultiBinding Converter="{x:Static BoolConverters.And}">
                        <Binding Path="Test"></Binding>
                        <Binding Path="Test1"></Binding>
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>

Expected behavior

No compiler error should be thrown, binding should work

Avalonia version

11.2.0-beta1

OS

No response

Additional context

No response

workgroupengineering commented 3 weeks ago

This issue was introduced by PR #16153.

Possible ways to solve it can be:

  1. Trim textValue before invoke XamlTransformHelpers.TryGetCorrectlyTypedValue at this line
  2. Replace Boolean.Parse with Boolean.TryParse at this line of XamlX
  3. Implement XamlAstTrivia and ingnore when xml:space is undefinited or default

my favorite is option 3 but it's probably the longest