The data context needs to get reassigned here
plucked opened this issue · 1 comments
plucked commented
Reproduce:
- Open the app
- Open some documents
- Close the app
- Open the app again
- Close some documents
You will see that the connection between the RadPane and the view model got lost, because the data context needs to get reassigned.
The fix in my code looks like this (using .net Core 3 with C# 8)
protected override void ElementLoadedOverride(string serializationTag, DependencyObject element) {
base.ElementLoadedOverride(serializationTag, element);
var model = DataSource.Panes.FirstOrDefault(viewModel => viewModel.SerializationTag == serializationTag);
if (model == null) {
return;
}
/// ... Control instancing code
// reassign the data context, otherwise we have no connection when it gets closed
if (element is FrameworkElement frameworkElement) {
frameworkElement.DataContext = model;
}
}
martinivanoff commented
Hello,
Can you tell me what do you mean by saying that the connection between the RadPane and the view model is lost? How do you indicate this?
Thank you for any help you can provide.
Regards,
Martin Ivanov
Telerik WPF Team