Skip to content

Commit

Permalink
fix: Remove ApplyDataContext method (deprecated) that's causing inval…
Browse files Browse the repository at this point in the history
…id data context
  • Loading branch information
nickrandolph committed Jun 20, 2024
1 parent c347914 commit 47dbddc
Showing 1 changed file with 0 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ private static void SwapViews(FrameworkElement oldView, FrameworkElement newView
parentAsContentControl = parentAsContentControl ?? (VisualTreeHelper.GetParent(oldView) as ContentPresenter)?.FindFirstParent<ContentControl>();
#endif

var parentDataContext = (parentAsContentControl as FrameworkElement)?.DataContext;

if ((parentAsContentControl?.Content as FrameworkElement) == oldView)
{
parentAsContentControl.Content = newView;
Expand Down Expand Up @@ -110,29 +108,6 @@ private static void SwapViews(FrameworkElement oldView, FrameworkElement newView
VisualTreeHelper.SwapViews(oldView, newView);
}
#endif

if (oldView is FrameworkElement oldViewAsFE && newView is FrameworkElement newViewAsFE)
{
ApplyDataContext(parentDataContext, oldViewAsFE, newViewAsFE);
}
}

private static void ApplyDataContext(object? parentDataContext, FrameworkElement oldView, FrameworkElement newView)
{
if (oldView == null || newView == null)
{
return;
}

if ((newView.DataContext is null || newView.DataContext == parentDataContext)
&& (oldView.DataContext is not null && oldView.DataContext != parentDataContext))
{
// If the DataContext is not provided by the page itself, it may
// have been provided by an external actor. Copy the value as is
// in the DataContext of the new element.

newView.DataContext = oldView.DataContext;
}
}
}
}

0 comments on commit 47dbddc

Please sign in to comment.