How to get reference to parent view controller in Cocoa? - macos

I know in CocoaTouch there is the parentViewController property for this but there seems to no such property in Cocoa for OSX development. How can I ref the parent view controller in a sub view controller?

Nevermind! I'm an idiot! I've checked for this in a View class, not in a View Controller class. The NSViewController does indeed have a parentViewController property.

Related

Unable to register VM through Prism Navigation

I'm creating WPF Core 3.1 app using Prism 7. In one of the view I am trying to register the view model for PRISM navigation through:
containerRegistry.RegisterForNavigation<ViewA, ViewAViewModel>();
And when required I do request to PRISM navigation service to navigate to the view using Region Manager
_regionManager.RequestNavigate(RegionNames.ContentRegion, "ViewA");
Navigation to the view is completed and I'm able to see the view on the defined region but the view model is not assigned to the view.
I tried to manually register the view model using the ViewModelLocationProvider but still the view model is not assigned.
ViewModelLocationProvider.Register<ViewA, ViewAViewModel>();
But if I use the PRISM Autowire property in the view then the view model is discovered and assigned to the view.
prism:ViewModelLocator.AutoWireViewModel="True"
View model class declared using IConfirmNavigationRequest interface required for navigation request handling
public class ViewAViewModel : RegionViewModelBase , IConfirmNavigationRequest
I am unable to figureout what I'm missing here.
The only thing I see wrong is that you would need to use the interface INavigationAware, not IConfirmNavigationRequest. I assume RegionViewModelBase implements BindableBase already.
public class ViewAViewModel : RegionViewModelBase, INavigationAware

Xamarin Forms Prism: Is INavigationService necessary to be passed in constructor? Any other way apart from constructor injection

For prism framework in xamarin forms, to navigate from one view to another, is it mandatory to implement constructor inject and pass INavigationService in ViewModel's constructor?
I Can perform Navigation when I pass INavigationService as
public SomeViewModel(INavigationService navigationService)
{
_navigationService.NavigateAsync("SomeOtherPage");
}
But when I try to resolve whenever its needed, it doesn't work
public SomeViewModel(INavigationService navigationService)
{
ContainerProvider.Resolve<T>();// ContainerProvider is IContainerProvider
}
Is there any other way to access INavigationService apart from constructor injection in every Viewmodel
What you’re describing is an anti pattern, and generally just poor design. It also will not work because the Navigation Service is a very special service. It is created especially for each ViewModel as the Navigation Service must have the context of the Page you are navigating from. Without it, it would only work for resetting the Navigation Stack. To attempt to resolve the Navigation Service any other way in the ViewModel would likely break the MVVM design pattern.
If you want to use the Navigation Service you must inject it via the constructor. You may also simply use XAML Navigation in Prism 7.1. You can see a sample with the Prism Tests. You can also see this in practice in this demo app.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xaml="clr-namespace:Prism.Navigation.Xaml;assembly=Prism.Forms"
Title="{Binding Title}"
x:Class="Prism.DI.Forms.Tests.Mocks.Views.XamlViewMockA">
<Button x:Name="testButton" Command="{xaml:NavigateTo 'XamlViewMockB'}">
<Button.CommandParameter>
<xaml:NavigationParameters>
<xaml:NavigationParameter Key="Foo" Value="Bar"/>
</xaml:NavigationParameters>
</Button.CommandParameter>
</Button>
</ContentPage>

Xamarin, How to invoke Shared code Method from Platform specific Dependency class

In Xamarin forms app, How can we invoke Shared code Method from Platform specific Dependency class.
I need to call one method implemented in my ContentPage class from my iOS dependency class.
Thanks...
There are different solutions to this:
Use a static method to call it where ever you need to.
Use the messaging center to send a message to your Shared/PCL project and do what ever you need. (link: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/messaging-center/)
If this is a Custom renderer you can use binded command properties and Execute those in your platforms specific code.
In my case, what I did was having a static class called Helper, that contains all the static methods that I need to call on all platforms/projects.
Hope this helps.

Binding to DataModel in MVVMCross

I have done the intro tutorial online and it works. My question is how does Mvvmcross know which View to associate with the ViewModel? There is nothing I can see in the code where they reference each other.
The default mode is by naming convention.
If your view is called "AwesomeView", Mvx will assign "AwesomeViewModel" to it at the app initialization.
When your view is instantiated, Mvx will "inject" the dependency (ViewModel) into your view as a binding context
So the convention to look up the view model is [ViewName]Model
If I´m correct this works using reflection

In ASP.NET MVC 3, what class does Views and Partial Views inherit from?

In ASP.NET MVC 3, what class doe Views and Partial Views inherit from and can the class (presumably it's a class somewhere) be inherited from to extend functionality.
For example, the default LogOnPartial control has the following (using Razor syntax)
Welcome <b>#Context.User.Identity.Name</b>!
Where is the Context object exposed. What class makes that available to the partial view?
They inherit from System.Web.Mvc.WebViewPage. http://msdn.microsoft.com/en-us/library/system.web.mvc.webviewpage%28VS.98%29.aspx In older versions of razor it was required to add the #inherits but newer versions don't.

Resources