diff --git a/.DS_Store b/.DS_Store index 8433f48..6de2beb 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/build.cake b/build.cake index eb3e96b..dcaae24 100644 --- a/build.cake +++ b/build.cake @@ -7,10 +7,6 @@ var settings = new DotNetCoreBuildSettings() Configuration = "Release", Sources = new List() {"https://api.nuget.org/v3/index.json","https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-6f411658/nuget/v3/index.json", "https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-1ec2e17f/nuget/v3/index.json"} }; - DotNetCoreBuild("src/Xamarin/TinyMvvm/TinyMvvm.csproj", settings); - DotNetCoreBuild("src/Xamarin/TinyMvvm.Forms/TinyMvvm.Forms.csproj", settings); - DotNetCoreBuild("src/Xamarin/TinyMvvm.Autofac/TinyMvvm.Autofac.csproj", settings); - DotNetCoreBuild("src/Xamarin/TinyMvvm.TinyIoC/TinyMvvm.TinyIoC.csproj", settings); DotNetCoreBuild("src/MAUI/TinyMvvm.Maui/TinyMvvm.Maui.csproj", settings); }); @@ -24,11 +20,6 @@ Task("Pack").IsDependentOn("Build").Does(() => Configuration = "Release", OutputDirectory = ".packages" }; - - DotNetCorePack("src/Xamarin/TinyMvvm/TinyMvvm.csproj", settings); - DotNetCorePack("src/Xamarin/TinyMvvm.Forms/TinyMvvm.Forms.csproj", settings); - DotNetCorePack("src/Xamarin/TinyMvvm.Autofac/TinyMvvm.Autofac.csproj", settings); - DotNetCorePack("src/Xamarin/TinyMvvm.TinyIoC/TinyMvvm.TinyIoC.csproj", settings); DotNetCorePack("src/MAUI/TinyMvvm.Maui/TinyMvvm.Maui.csproj", settings); }); diff --git a/docs/GetStarted.md b/docs/GetStarted.md deleted file mode 100644 index c2665cd..0000000 --- a/docs/GetStarted.md +++ /dev/null @@ -1,252 +0,0 @@ -# TinyMvvm Get Started Tutorial -This is a tutorial that will guide you through how to get started building an app using Xamarin.Forms and TinyMvvm. - -1. Create a new project based on the template for a **blank** Xamarin.Forms app. In this example, the name of the project will be **SampleApp**. The template will generate one project for shared code and one project per target platform. -1. Install the following NuGet packages into all projects: - * TinyMvvm.Forms - * TinyMvvm.Autofac -1. Create a new **ContentPage XAML** in the **SampleApp** project and give it the name **AppShell**. And add the following content to it. - ```xml - - - - - - - - - - - ``` - -1. Remove the base class in the AppShell.xaml.cs so it will look like this: - ```csharp - public partial class AppShell - { - public AppShell() - { - InitializeComponent(); - } - } - ``` -1. Navigate to **App.xaml.cs** and set **MainPage** to **AppShell**. You can also delete the MainPage.xaml- and MainPage.xaml.cs files. - ```csharp - public partial class App : Application - { - public App() - { - InitializeComponent(); - - MainPage = new AppShell(); - } - } - ``` -1. On the rows before you set MainPage to AppShell write the initialization code for TinyMvvm: - * Use **ShellNavigationHelper** and register all views in the current Assembly. This register all views so we can use the class name as the key if we use the classic (non-Shell) navigation or we can use ViewModelNavigation that is powered by the Shell navigation. - * The sample is using **Autofac** as it's **IoC container**, but you can use whatever container you want. The only thing you need to do to use another is to create an implementation of **IResolver** that uses it. Register all classes that is a subType of **Page** (Xamarin.Forms) and **ViewModelBase** (TinyMvvm). - * Register the container to the Resolver, the **Resolver** is used internally by TinyMvvm, but you can also use it in your code. - - ```csharp - public App() - { - InitializeComponent(); - - var navigationHelper = new ShellNavigationHelper(); - - var currentAssembly = Assembly.GetExecutingAssembly(); - navigationHelper.RegisterViewsInAssembly(currentAssembly); - - var containerBuilder = new ContainerBuilder(); - - containerBuilder.RegisterInstance(navigationHelper); - - var appAssembly = typeof(App).GetTypeInfo().Assembly; - containerBuilder.RegisterAssemblyTypes(appAssembly) - .Where(x => x.IsSubclassOf(typeof(Page))); - - containerBuilder.RegisterAssemblyTypes(appAssembly) - .Where(x => x.IsSubclassOf(typeof(ViewModelBase))); - - var container = containerBuilder.Build(); - - Resolver.SetResolver(new AutofacResolver(container)); - - MainPage = new AppShell(); - } - ``` -1. Create a new folder called **ViewModels** in the **SampleApp** project. -1. Create two classes in the ViewModels folder, **MainViewModel** and **AboutViewModel**. -1. Add **ViewModelBase** as the base class for MainViewModel and AboutViewModel: - ```csharp - public class MainViewModel : ViewModelBase - { - public MainViewModel() - { - } - } - ``` - - ```csharp - public class AboutViewModel : ViewModelBase - { - public AboutViewModel() - { - } - } - ``` -1. Create a new folder called **Views** in the **SampleApp** project. -1. Create two new **ContentPage XAML** pages in the Views folder, **MainView** and **AboutView**. -1. Edit **MainView.xaml** and **AboutView.xaml** to have **ViewBase** as it's base class. To set BindingContext to the the ViewModel, use the **x:TypeArguments** for the View. - ```xml - - - - ``` - ```xml - - - - ``` -1. Remove the base class from **MainView.xaml.cs** and **AboutView.xaml.cs**. Because is it a partial class you don't have to specify it both in the XAML-file and in the code-behind file. -1. Create a new View, **DetailsView**, and a new ViewModel, **DetailsViewModel** as in the same style as above. -1. In MainViewModel, add the following below. The override of **Initialize** is running when **BindingContext** for the view has been set. You can also override **OnAppearing** to run code when the view will appear and **OnDisappearing** to run code when the view will disappear. **IsBusy** can be used to bind an **ActivityIndicator** to. For Commands, use **TinyCommand** instead of **Xamarin.Forms.Command** to keep the ViewModel clean from Xamarin.Forms references. To navigate, use the **Navigation** property from **ViewModelBase**. Here you can use the name of a ViewModel as a part of a URL to navigate to a route. With TinyMvvm you can also specify a parameter to pass to the target ViewModel. - ```csharp - public class MainViewModel : ViewModelBase - { - private ObservableCollection names; - public ObservableCollection Names - { - get => names; - set => Set(ref names, value); - } - - public async override Task Initialize() - { - IsBusy = true; - await base.Initialize(); - - Names = new ObservableCollection(new List() - { - "Daniel", - "Ella", - "Willner" - }); - - IsBusy = false; - } - - public override Task OnAppearing() - { - return base.OnAppearing(); - } - - public override Task OnDisappearing() - { - return base.OnDisappearing(); - } - - private ICommand details; - public ICommand Details => details ??= new TinyCommand(async(name) => - { - await Navigation.NavigateToAsync($"{nameof(DetailsViewModel)}?name={name}", DateTimeOffset.Now); - }); - } - ``` -1. To **MainView.xaml** add the following code to show the bind a **CollectionView** to the data in the ViewModel: - ```xml - - - - - - - - - - - - - - - ``` -1. Go to DetailsViewModel.cs and add the code below to receive the parameters sent to it. **QueryParameters** will be a **Dictionary** and contains the query parameters specified in the navigation URL. If you also specified a parameter you can access it via the **NavigationParameter** property. - ```csharp - public class DetailsViewModel : ViewModelBase - { - public async override Task Initialize() - { - await base.Initialize(); - - Name = QueryParameters["name"]; - var dateParameter = (DateTimeOffset)NavigationParameter; - - Date = dateParameter.ToString(); - } - - private string name; - public string Name - { - get => name; - set => Set(ref name, value); - } - - private string date; - public string Date - { - get => date; - set => Set(ref date, value); - } - } -1. In the **DetailsView.cs** add the following code to show the data passed from MainViewModel: - ```xml - - - - - ``` -1. Navigate to **AboutViewModel.cs** and add the following code to use with a button to navigate to the MainView using the route specified in the **Shell**. - ```csharp - public class AboutViewModel : ViewModelBase - { - private ICommand home; - public ICommand Home => home ?? new TinyCommand(async () => - { - await Navigation.NavigateToAsync("//home"); - }); - } - ``` -1. Go to **AboutView.xaml** and create a Button to use with the Command in **AboutViewModel**. - ```xml - - -