Skip to content
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

PropertyChanged gives exception for enum columns #293

Open
blackmole opened this issue Jun 2, 2024 · 1 comment
Open

PropertyChanged gives exception for enum columns #293

blackmole opened this issue Jun 2, 2024 · 1 comment

Comments

@blackmole
Copy link

Setup:
TreeDataGrid with a column that contains an enum.

Action:
The model raises a PropertyChanged event for the enum.

Expected behavior:
The TreeDataGrid updates the cell to the new enum value.

Observed behavior:
A System.InvalidCastException is triggered.

Workaround tried:
I used an IValueConverter for the conversion between the enum and strings. Did not change anything.

Apparently the way the data is displayed normally and the way the data is updated are different.
Example for this issue: https://github.com/blackmole/AvaloniaComboBoxEnum

@blackmole
Copy link
Author

So what happens is this chain: TextCell.Value is changed --> TreeDataGridTextCell.Value is changed which sets TextCell.Text which tries to convert the text back to the enum. And which is unnecessary because the TextCell.Value is already correct.
Not sure what the clean solution is, but I guess it might work to change the TextCell.Text setter to:

set
{
    if (value != _value?.ToString()) 
         Value = (T?)Convert.ChangeType(value, typeof(T));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant