Closed acrolink closed 10 hours ago
I have solved the issue by adding a DATA property to the controller, see the commit at my forked repo. Maybe should be considered in future release?
https://github.com/acrolink/WPF_MVVMC/commit/af18752af956c83b3d01bf86a866a5e712860894
Hi, You can get the controller instance and set whatever properties you want to the object. i.e.
var controller = _navigationService.GetController<MyController>();
controller.MyDataProperty = data;
If you want to do something when a controller is created, you can subscribe to the ControllerCreated event
MVVMCNavigationService.ControllerCreated += (controllerId)=> {
var controller = MVVMCNavigationService.GetController(controllerId);
if (controller is MyController)
{
controller.MyDataProperty = data;
}
}
Does that help with your use case?
Another suggestion: When you're in the MainWindow code-behind, you have the Region
control that's tied to the controller. You can get the controllerId directly from the region and set whatever data you need.
var region = MyRegion; // assuming the region's x:name in XAML is "MyRegion"
var controller = _navigationService.GetController(region.ControllerID) as My Controller;
controller.MyDataProperty = data;
@michaelscodingspot
I have tried this:
var controller = _navigationService.GetController<WizardController>();
controller.MyDataProperty = data;
But getting this error message:
Sequence contains no matching element
@michaelscodingspot
I have tried this:
var controller = _navigationService.GetController<WizardController>(); controller.MyDataProperty = data;
But getting this error message:
Sequence contains no matching element
This works indeed, only if done inside the ContentRendered
event.
Great! I'm closing this issue. Feel free to reopen this one or a new one if you're still having trouble.
e.g. when opening the MainWindow holding it?