This repository was archived by the owner on Aug 27, 2020. It is now read-only.
-
Couldn't load subscription status.
- Fork 37
DependencyServiceExtension
Mark Smith edited this page Aug 29, 2016
·
1 revision
The DependencyServiceExtension is a markup extension that provides access to the Xamarin.Forms DependencyService.Get static method in XAML.
-
FetchTarget: theDependencyFetchTarget(GlobalInstance or NewInstance) to retrieve. Defaults toGlobalInstance. -
Type: theSystem.Typeto retrieve. This is required and is the default content for the extension when used in XAML.
We could register a ViewModel in our App constructor:
public class App
{
public App()
{
DependencyService.Register<MainViewModel,MainViewModel>();
}
...
}and then find that dependency in XAML and set it to our binding context:
<Page xmlns:inf="clr-namespace:XamarinUniversity.Infrastructure;assembly=XamU.Infrastructure" ...
BindingContext="{inf:DependencyService {x:Type vm:MainViewModel}}">