telerik/xaml-sdk

The data context needs to get reassigned here

plucked opened this issue · 1 comments

base.ElementLoadedOverride(serializationTag, element);

Reproduce:

  1. Open the app
  2. Open some documents
  3. Close the app
  4. Open the app again
  5. 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;
            }
        }

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