-
Notifications
You must be signed in to change notification settings - Fork 1.9k
XAMLC is failing on valid StringFormat #5152
Comments
I believe we should only be throwing an exception if the StringFormat starts with a curly brace, not if it contains one. |
Would this change allow this format, contrived I know, but still valid?
|
@stevehurcombe doesn't look valid to me |
What's wrong with it exactly? This is an example from the documentation:
Are you saying that this isn't valid?
|
OK, so I've been reading into the background of this. The solution doesn't seem like a great one, it's non-obvious and smells. People are going to be tripping up over this error for years to come for little perceived value, even if it is technically correct. Surely the fact that it's part of an inner single quoted string mitigates the issue? The start of the string is surely There must be a better way... |
@StephaneDelcroix @stevehurcombe Now Invalid:
Valid:
|
This issue shouldn't have been closed. The fix in #5169 Improves the situation, but it still forces edits to StringFormats that are valid according to the XAML spec. The Microsoft documentation on this is unambiguous:
Further, the documentation for StringFormat in WPF clearly shows examples both with and without the braces, where the opening empty braces are only used to break out of the markup extension:
I've left a corresponding comment on the original issue reported to Visual Studio |
@jalbertSyncroTech that doc doesn't mention escape sequence
I understand the frustration, because some strings used to get correctly parsed by XF and no longer are, but I'm happy that the current XF is more correct than before. |
@StephaneDelcroix I realize this is a complex issue, but the reading of the XAML Markup Extension Parsing doc is unambiguous:
As an example: |
@stevehurcombe I think it does: I just tested calling However, It all comes down to the single-quote behavior follow the spec. |
I read through the full parser documentation again, and it's even more confusing than the above discussion: The "Markup Extension Parsing" doesn't define anything about recursive markup extensions when assigning member values, it seems like that behavior is entirely up to parent extension, BindingExtension in this case. When it comes to single vs. no-quotes, for the no-quotes variation the The question comes down to how BindingExtension determines how to assign the text value from the parser to the StringFormat member. |
Yeah, I can kind of see the argument for both but like you said, the spec does not address nested markup extensions, and the WPF compiler produces a build error for the following (with or without quotes):
The only way to avoid the build error is to prefix it with the {} escape sequence. That’s why we have always marked it as an error. |
So you're saying this is an edge case issue in the WPF compiler? :-) This is surely the preferred syntax: |
I choose to think of it more as the WPF compiler setting a precedent. :-) That said, we don't want to be stuck in the past. If the consensus for Xamarin Forms is to treat any nested "MarkupExtensions" as literal text if they are surrounded by quotes then we will need to make the changes in the language service to no longer try to interpret those as MarkupExtensions either (for Xamarin Forms). |
@stevehurcombe I think rather that the spec doesn't make any distinction between quotes and no quotes in the final parsed text - it seems like quotes really just get you the ability to use commas and equal signs without tripping up the parser. The issue for my team is that the behavior of Xamarin.Forms both before and after this change were different from WPF. Before you didn't need the opening I think we're good now, since at least we match both the spec and the old WPF behavior, but the ongoing argument is about if Xamarin.Forms can unambiguously identify a string from a markup extension without needing the opening braces then why is it requiring them? In other words, if it's a nested MarkupExtension then you never need the quotes and the convention is to not use them, so why not just make the use of quotes always mean the value should be interpreted as a literal string. |
I think there are two arguments. I, at least, am petitioning for this format to be supported:
We have a chance here to either be famous for 15 minutes on this thread, or be infamous for the next 10 years as newbie XF developers trip over this syntax and end up here! It might be to the spec, but it's not a good solution IMHO. There is an opportunity to correct that before it goes out into the main releases. |
Description
I upgraded the FormsGallery from 3.4.0 to 3.6-pre1 and it now throws the XAMLC error:
This is happening everywhere StringFormat is being used, such as:
StringFormat from the docs:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/string-formatting#the-stringformat-property
When I disabled XAMLC the app runs fine.
Expected Behavior
XAMLC passes
Actual Behavior
XAMLC produces the above error.
Basic Information
Reproduction Link
https://developer.xamarin.com/samples/xamarin-forms/FormsGallery/
The text was updated successfully, but these errors were encountered: