-
Notifications
You must be signed in to change notification settings - Fork 60
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 option to text cells. #313
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this! Just one small potential suggestion to make things easier for consumers. Not blocking at all 🤷
/// <summary> | ||
/// Gets the format string to be used to format the cell value. | ||
/// </summary> | ||
string StringFormat { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this won't be possible since ITextCellOptions is not generic and passing in the type of the property for the column but I thought I'd bring it up just in case you see a way to make it happen!
It would be nice to decorate the property with [StringSyntax(StringSyntaxAttribute.NumericFormat)]
or any of the other derivatives.
Again, I don't think this would work HERE but it would be cool to be able to specify the stringsyntax somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, couldn't the string format be anything at all though? I can imagine it being using for displaying arbitrary strings in the cells, e.g. "{0} apple(s)"
. The StringFormat
in standard Binding
s can certainly be used that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! I was thinking of having it set according to the TModel type, but you're right that the possibilities are so varied, I don't think it's worth going through all this trouble.
/// <summary> | ||
/// Gets or sets the format string for the cells in the column. | ||
/// </summary> | ||
public string StringFormat { get; set; } = "{0}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw that we have the TModel
here! Might be able to use StringSyntaxAttribute
after all?
This is similar to #283, but I used a slightly difference approach as the feature in that PR caused problems when text cells were edited.
The differences are:
TextCell
) rather than in the view layer (TreeDataGridTextCell
) - this allows us to keep the edited text and the underlying value separate. This prevents the exception when editing.CurrentCulture
rather thanInvariantCuture
. This aligns with standard Avalonia bindings