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

Add StringFormat to Binding. #1684

Merged
merged 8 commits into from Aug 13, 2018

Conversation

3 participants
@grokys
Member

grokys commented Jun 20, 2018

This PR implements Binding.StringFormat. It works almost identically to the WPF feature with one difference: it also works for bindings applied to properties of type object (WPF's only works for bindings to string) which means it can be applied to e.g. ContentControl.Content.

It is implemented as an IValueConverter: StringFormatValueConverter. When StringFormat is applied to a binding, a StringFormatValueConverter is used as the converter on the BindingExpression with the binding's Converter chained in via the StringFormatValueConverter.Inner value converter.

Note: The curly braces in the format string in XAML currently need to be escaped with a \ character due to cwensley/Portable.Xaml#106.

Note: This does not add StringFormat to MultiBinding - that will be a separate PR.

Fixes #821

@grokys grokys changed the title from WIP: Adding of StringFormat. to WIP: Adding StringFormat to Binding. Jun 20, 2018

@grokys grokys changed the title from WIP: Adding StringFormat to Binding. to Adding StringFormat to Binding. Jun 21, 2018

grokys added some commits Jun 21, 2018

@grokys grokys requested a review from AvaloniaUI/core Jun 21, 2018

@grokys grokys changed the title from Adding StringFormat to Binding. to Add StringFormat to Binding. Jun 21, 2018

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
value = Inner?.Convert(value, targetType, parameter, culture) ?? value;
return string.Format(Format, value, culture);

This comment has been minimized.

@Karnah

Karnah Jun 22, 2018

Contributor

May be return string.Format(culture, Format, value);?

This comment has been minimized.

@grokys

grokys Jun 22, 2018

Member

Oops! Good catch!

@grokys grokys added this to the 0.7.0 milestone Jul 5, 2018

@grokys grokys added this to To do in 0.7.0 blockers Jul 5, 2018

@jkoritzinsky jkoritzinsky moved this from To do to In progress in 0.7.0 blockers Jul 11, 2018

@jkoritzinsky

LGTM

@jkoritzinsky jkoritzinsky merged commit 5289ddd into master Aug 13, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

0.7.0 blockers automation moved this from In progress to Done Aug 13, 2018

@jkoritzinsky jkoritzinsky deleted the feature/stringformat branch Aug 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment