Fix TreeDataGridTextCell changing TextCell.Value #304
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.
TreeDataGridTextCell
listens to property changes ofITextCell.Value
to update its ownValue
property. The setter ofTreeDataGridTextCell.Value
updatesITextCell.Text
to the string representation of the new value.This is done because the cell can be edited, and
TreeDataGridTextCell.Value
is bound toTextBox.Text
two-way when the user wants to edit the cell.However,
TextCell<T>.Text
which the setter ofTreeDataGridTextCell.Value
will always set, doesn't respect the read-only status or the editing status of the cell:TextCell<T>.Value
updates.TreeDataGridTextCell
reacts and setsTreeDataGridTextCell.Value
to the string representation of the new value.
TreeDataGridTextCell.Value
will setTextCell<T>.Text
to the string representation.
TextCell<T>.Text
will try to convert the textrepresentation 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
ofTextCell<T>
fails to convert:Convert.ChangeType(value, typeof(T))
. This obviously isn't an issue whenT
isstring
but it does have issues for base types like numbers (localization issues), and custom types will almost always result in an exception.