Breaks with V4.5.0 Pre Release 1
I have a binding like so:
Colors="{styling:ColorList 'AccentButtonTextColour' }"
but I get the error:
Empty value string in markup expression
I could remove the apostrophes, but If I have a binding with a comma in it then I can't like so:
Colors="{styling:ColorList 'AccentButtonTextColour,AccentButtonTextColour2' }"
Works again if I downgrade to stable
please provide your markup extension code. thanks
@StephaneDelcroix
My Markup code is:
[ContentProperty("Text")]
public class ColorListExtension : IMarkupExtension
{
public string Text { get; set; }
//This errors on a page "Specified Cast is invalid". and doesnt work in a style
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Text == null)
throw new Exception("No Colors Provided");
return StylingLookup.GetColorList(Text);
}
}
extra info: think this happens more when the extension is used on the property of a control in a datatemplate?
BTW this is also a regression from 4.4.0. May help when triaging
This also prevents from using StringFormat
in bindings:
<Label Text="{Binding Amount, StringFormat='$ {0}'}" />
One way around this issue is to use a String Resource in your XAML
For my case where I had
<ColumnDefinition Width="{Binding IsDashboardFullScreen, Converter={StaticResource BoolToGridLengthConverter}, ConverterParameter='0,1'}" />
I was able to replace it with
```
```
I'm unable to reproduce this issue on 4.4.0 (as expected), 4.5.0-pre1 or the HEAD of the 4.5.0 branch.
I pushed a unit test for this on the 4.5.0 branch https://github.com/xamarin/Xamarin.Forms/commit/8205d408462aa7a5f6f2e99936640fa2fb98b73e
@JKennedy24 @dirivero if you think this bug still exists, I'd need a small and contained reproduction project for it. Thanks.
@StephaneDelcroix it only happens with 4.5. In previous versions it did work as far as I know.
I've run a few more tests because I couldn't reproduce the issue with my own sample Label above (sorry about that). I've found that the problem happens if you add a white space after the '
.
Works:
<Label Text="{Binding Amount, StringFormat='$ {0}'}" />
Doesn't work (error: Empty value string in markup expression)
<Label Text="{Binding Amount, StringFormat='$ {0}' }" />
It also fails with a new line (the one after 'iOS'
):
<Label Text="{
OnPlatform
Android='android',
iOS='iOS'
}" />
If you update your test case XAML code by adding a white space at the end it should fail as well:
<Label x:Name="label" Text="{local:Gh9212Markup 'Foo, Bar' }" />
Repro project here Issue9212.zip
Thanks!
@dirivero It could be the added whitespace that is causing it! I could never work out why some views were fine and others wouldn't compile.
Only happened on version greater than 4.5.0-Pre1
@dirivero It could be the added whitespace that is causing it! I could never work out why some views were fine and others wouldn't compile.
Only happened on version greater than 4.5.0-Pre1
Whitespace seems to be the issue. Great catch!!!
This fails (note the space between the end apostrophe and the last closing bracket)
<ColumnDefinition Width="{Binding IsDashboardFullScreen, Converter={StaticResource BoolToGridLengthConverter}, ConverterParameter='0,*' }"
This works!
<ColumnDefinition Width="{Binding IsDashboardFullScreen, Converter={StaticResource BoolToGridLengthConverter}, ConverterParameter='0,*'}"
thx for the additional tests @dirivero, the trailing space is indeed what causes the issue. working on it
bug introduced by #8980
@StephaneDelcroix Thank you for addressing this! Two questions:
When will this be released to NuGet?
Confirmed fix is out in 4.5.0-sr2 (4.5.0.495 out on nuget)! 馃檶
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/4.5/4.5.0-sr2
And yes, it does also handle newlines. 馃槉
Thanks @StephaneDelcroix !
Most helpful comment
@StephaneDelcroix it only happens with 4.5. In previous versions it did work as far as I know.
I've run a few more tests because I couldn't reproduce the issue with my own sample Label above (sorry about that). I've found that the problem happens if you add a white space after the
'
.Works:
Doesn't work (error: Empty value string in markup expression)
It also fails with a new line (the one after
'iOS'
):If you update your test case XAML code by adding a white space at the end it should fail as well:
Repro project here Issue9212.zip
Thanks!