Skip to content

Instantly share code, notes, and snippets.

@usausa
Created February 26, 2019 08:01
Show Gist options
  • Save usausa/71d82757067128cb0c3dfab62d160695 to your computer and use it in GitHub Desktop.
Save usausa/71d82757067128cb0c3dfab62d160695 to your computer and use it in GitHub Desktop.
dseign-time BindingContext and runtime resolve
public class AppViewModelBase<T> : ViewModelBase
where T : AppViewModelBase<T>
{
public static T DesignInstance { get; } = null; // For design
}
<?xml version="1.0" encoding="UTF-8" ?>
<ContentView x:Class="FormsApp.Modules.MenuView"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:modules="clr-namespace:FormsApp.Modules;assembly=FormsApp"
xmlns:resolver="clr-namespace:Smart.Forms.Resolver;assembly=Smart.Forms"
BindingContext="{Binding Source={x:Static modules:MenuViewModel.DesignInstance}}"
resolver:BindingContextResolver.Type="{x:Type modules:MenuViewModel}">
</ContentView>
public class MenuViewModel : AppViewModelBase<MenuViewModel>
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment