You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a parent view where there is a subregion. I navigate to the parent view through a button, and when I leave the view, the OnNavigatedFrom method is triggered normally. However, the subregion does not trigger OnNavigatedFrom. I would like to know if there is any way to make the lifecycle of the subregion consistent with the parent view.
This is my current code.
<ContentControl Grid.Column="1" Margin="5" DockPanel.Dock="Left"
prism:RegionManager.RegionName="UploadMaterialRegion"/>
public void OnNavigatedTo(NavigationContext navigationContext)
{
_regionManager.RequestNavigate("UploadMaterialRegion", "TruckListView");
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{if (_regionManager.Regions.ContainsRegionWithName("UploadMaterialRegion"))
{
var region = _regionManager.Regions["UploadMaterialRegion"];
if (region != null && region.Views.Any())
{
foreach(var view in region.Views)
{
// 通过 DataContext 获取 ViewModel
if (view is FrameworkElement frameworkElement &&
frameworkElement.DataContext is INavigationAware navigationAware)
{
navigationAware.OnNavigatedFrom(navigationContext);
}
}
region.RemoveAll();
}
}
}
I achieved it manually by triggering remove now, but I think it's not very reasonable or elegant. Is there a more elegant solution?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a parent view where there is a subregion. I navigate to the parent view through a button, and when I leave the view, the OnNavigatedFrom method is triggered normally. However, the subregion does not trigger OnNavigatedFrom. I would like to know if there is any way to make the lifecycle of the subregion consistent with the parent view.
This is my current code.
I achieved it manually by triggering remove now, but I think it's not very reasonable or elegant. Is there a more elegant solution?
Beta Was this translation helpful? Give feedback.
All reactions