Skip to content

Commit

Permalink
fix IViewModelLocator not found (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibel committed Aug 20, 2023
1 parent 9774347 commit e2bba7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Caliburn.Light.WPF/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ private static void CreateView(FrameworkElement parentElement, object model, str
return;
}

if (!parentElement.IsLoaded)
{
ExecuteOnLoad(parentElement, x => CreateView(x, x.DataContext, GetContext(x)));
return;
}

var viewModelLocator = GetCurrentViewModelLocator(parentElement);
if (viewModelLocator is null)
throw new InvalidOperationException("Could not find 'IViewModelLocator' in control hierarchy.");
Expand Down
6 changes: 6 additions & 0 deletions src/Caliburn.Light.WinUI/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ private static void CreateView(FrameworkElement parentElement, object model, str
return;
}

if (!parentElement.IsLoaded)
{
ExecuteOnLoad(parentElement, x => CreateView(x, x.DataContext, GetContext(x)));
return;
}

var viewModelLocator = GetCurrentViewModelLocator(parentElement);
if (viewModelLocator is null)
throw new InvalidOperationException("Could not find 'IViewModelLocator' in control hierarchy.");
Expand Down

0 comments on commit e2bba7d

Please sign in to comment.