Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] FormattedText should have an implicit converter from IList<Span> #13112

Open
softlion opened this issue Dec 11, 2020 · 2 comments
Labels
a/label e/1 🕐 1 proposal-open t/enhancement ➕ up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!

Comments

@softlion
Copy link
Contributor

softlion commented Dec 11, 2020

Summary

Currently to use the FormattedText property you need to add a FormattedString tag:

<Label>
<Label.FormattedText>
    <FormattedString>
         <Span Text="Some text" />
         <Span Text=": " />
     </FormattedString>
</Label.FormattedText>
</Label>

This is a lot of verbosity that can be shrinked easily by adding a TypeConverter on the FormattedText property of the Label, which would converts an IList<Span> into a FormattedString.

The simplification will leads to this more readable and much less verbose xaml:

<Label>
<Label.FormattedText>
     <Span Text="Some text" />
     <Span Text=": " />
</Label.FormattedText>
</Label>

To go further, the default Content property on the Label could be set to FormattedText leading to this xaml:

<Label>
   <Span Text="Some text" />
   <Span Text=": " />
</Label>

API Changes

none

@samhouts samhouts added this to New in Triage Dec 11, 2020
@PureWeen PureWeen added this to Under consideration in Enhancements via automation Dec 11, 2020
@PureWeen PureWeen removed this from New in Triage Dec 11, 2020
@PureWeen PureWeen added up-for-grabs We welcome community contributions to any issue, but these might be a good place to start! e/1 🕐 1 labels Dec 11, 2020
@BrayanKhosravian
Copy link
Contributor

BrayanKhosravian commented Nov 28, 2021

How would this be implemented?
The ContentProperty of the Label is already set to the Label.Text property which is of type string.
As far as I know, it is not possible to add another ContentPropertyAttribute to the label class.

I can currently think of 3 solutions:

  1. Use a converter which accepts string or IList<Span>.
  2. Make it possible to define more then one ContentProperyAttribute.
    This would mean that the identification of which ConentProperty is used has to be emitted and applied during runtime.
  3. Add a new "MultiContentPropertyAttribute" which accepts multiple properties and selects the property which is used.
    This would result in extending existing code but not modifying it.

@softlion
Copy link
Contributor Author

softlion commented Nov 28, 2021

Hello !

The ContentProperty of the Label could be an object instead of a string. So it can be either a string or a list of spans.
A converter on it would make the decision.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/label e/1 🕐 1 proposal-open t/enhancement ➕ up-for-grabs We welcome community contributions to any issue, but these might be a good place to start!
Projects
Enhancements
  
Under consideration
Development

No branches or pull requests

4 participants