This repository was archived by the owner on Oct 13, 2025. It is now read-only.
Fix TreeDataGridTextCell changing TextCell.Value#304
Open
erri120 wants to merge 1 commit intoAvaloniaUI:masterfrom
Open
Fix TreeDataGridTextCell changing TextCell.Value#304erri120 wants to merge 1 commit intoAvaloniaUI:masterfrom
erri120 wants to merge 1 commit intoAvaloniaUI:masterfrom
Conversation
Author
|
The target.Text = "new";without using |
erri120
added a commit
to erri120/NexusMods.App
that referenced
this pull request
Sep 4, 2024
43dc03a to
51f0a41
Compare
`TreeDataGridTextCell` listens to property changes of `ITextCell.Value`
to update its own `Value` property. The setter of `TreeDataGridTextCell.Value`
updates `ITextCell.Text` to the string representation of the new value.
This is done because the cell can be edited, and
`TreeDataGridTextCell.Value` is bound to `TextBox.Text` two-way when the
user wants to edit the cell.
However, `TextCell<T>.Text` which the setter of `TreeDataGridTextCell.Value`
will always set, doesn't respect the read-only status or the editing
status of the cell:
1) `TextCell<T>.Value` updates.
2) `TreeDataGridTextCell` reacts and sets `TreeDataGridTextCell.Value`
to the string representation of the new value.
3) The setter of `TreeDataGridTextCell.Value` will set `TextCell<T>.Text`
to the string representation.
4) The setter of `TextCell<T>.Text` will try to convert the text
representation of the new value as the new value...
If it weren't for the fact that `RaiseAndSetIfChanged` does what it's
supposed to do, which is only raise if changed, this would be a loop
that goes on forever.
Users will get an exception if `T` of `TextCell<T>` fails to convert:
`Convert.ChangeType(value, typeof(T))`. This obviously isn't an issue
when `T` is `string` but it does have issues for base types like numbers
(localization issues), and custom types will almost always result in an
exception.
51f0a41 to
5cda498
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TreeDataGridTextCelllistens to property changes ofITextCell.Valueto update its ownValueproperty. The setter ofTreeDataGridTextCell.ValueupdatesITextCell.Textto the string representation of the new value.This is done because the cell can be edited, and
TreeDataGridTextCell.Valueis bound toTextBox.Texttwo-way when the user wants to edit the cell.However,
TextCell<T>.Textwhich the setter ofTreeDataGridTextCell.Valuewill always set, doesn't respect the read-only status or the editing status of the cell:TextCell<T>.Valueupdates.TreeDataGridTextCellreacts and setsTreeDataGridTextCell.Valueto the string representation of the new value.
TreeDataGridTextCell.Valuewill setTextCell<T>.Textto the string representation.
TextCell<T>.Textwill try to convert the textrepresentation of the new value as the new value...
If it weren't for the fact that
RaiseAndSetIfChangeddoes what it's supposed to do, which is only raise if changed, this would be a loop that goes on forever.Users will get an exception if
TofTextCell<T>fails to convert:Convert.ChangeType(value, typeof(T)). This obviously isn't an issue whenTisstringbut it does have issues for base types like numbers (localization issues), and custom types will almost always result in an exception.