Skip to content

Commit

Permalink
Merge pull request #32 from egvijayanand/working
Browse files Browse the repository at this point in the history
v1.9.0
  • Loading branch information
egvijayanand committed Jun 24, 2024
2 parents 75abed8 + deedda3 commit 3055465
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 47 deletions.
40 changes: 23 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

Join me on [**Developer Thoughts**](https://egvijayanand.in/), an exclusive blog for Xamarin.Forms, .NET MAUI, and Blazor with articles on working with it.

Consult this [Xamarin.Forms Templates](https://egvijayanand.in/2024/01/26/introducing-xamarin-forms-templates/) article for further details.

#### Available to install from

|NuGet|VS Marketplace|
|:---:|:---:|
|[![VijayAnand.FormsTemplates - NuGet Package](https://badgen.net/nuget/v/VijayAnand.FormsTemplates/?icon=nuget)](https://www.nuget.org/packages/VijayAnand.FormsTemplates/)|[![Xamarin.Forms Project and Item Templates - VS Marketplace](https://badgen.net/vs-marketplace/v/egvijayanand.xamarin-forms-templates?icon=visualstudio&foo=bar)](https://marketplace.visualstudio.com/items?itemName=egvijayanand.xamarin-forms-templates)|
|[![VijayAnand.FormsTemplates - NuGet Package](https://badgen.net/nuget/v/VijayAnand.FormsTemplates/?icon=nuget&foo=bar)](https://www.nuget.org/packages/VijayAnand.FormsTemplates/)|[![Xamarin.Forms Project and Item Templates - VS Marketplace](https://badgen.net/vs-marketplace/v/egvijayanand.xamarin-forms-templates?icon=visualstudio&foo=bar)](https://marketplace.visualstudio.com/items?itemName=egvijayanand.xamarin-forms-templates)|

#### Access within Visual Studio IDE

Expand Down Expand Up @@ -47,7 +49,7 @@ dotnet new update

Project template for Xamarin.Forms 5 Class Library and is named as `formsclasslib`

Class library project template take the below optional parameters to override its target framework and to include the officially supported [Xamarin.CommunityToolkit](https://www.nuget.org/packages/Xamarin.CommunityToolkit), [Xamarin.CommunityToolkit.Markup](https://www.nuget.org/packages/Xamarin.CommunityToolkit.Markup), [Xamarin.Essentials](https://www.nuget.org/packages/Xamarin.Essentials), [CommunityToolkit.Mvvm](https://www.nuget.org/packages/CommunityToolkit.Mvvm) (aka Microsoft MVVM Toolkit), [VijayAnand.Toolkit.Markup](https://www.nuget.org/packages/VijayAnand.Toolkit.Markup) (the Shared Toolkit) or all NuGet packages:
Class library project template take the below optional parameters to override its target framework and to include the officially released [Xamarin.Forms.Maps](https://www.nuget.org/packages/Xamarin.Forms.Maps), [Xamarin.CommunityToolkit](https://www.nuget.org/packages/Xamarin.CommunityToolkit), [Xamarin.CommunityToolkit.Markup](https://www.nuget.org/packages/Xamarin.CommunityToolkit.Markup), [Xamarin.Essentials](https://www.nuget.org/packages/Xamarin.Essentials), [CommunityToolkit.Mvvm](https://www.nuget.org/packages/CommunityToolkit.Mvvm) (aka Microsoft MVVM Toolkit), [VijayAnand.Toolkit.Markup](https://www.nuget.org/packages/VijayAnand.Toolkit.Markup) (aka Shared Toolkit) or all NuGet packages:

* `-f` | `--framework` - Default value is `netstandard2.0`
* `-asp` | `--all-supported-packages` - Default value is `false`
Expand All @@ -59,9 +61,10 @@ Class library project template take the below optional parameters to override it

Explicit option:

* `-inm` | `--include-maps` - Default value is `false`
* `-iei` | `--include-essentials-interfaces` - Default value is `false`

*Note: The NuGet package version being added out-of-the-box are v2.0.x for the Xamarin Toolkit packages, v1.8.x for the Xamarin.Essentials package, and v8.2.x for the MVVM Toolkit package.*
*Note: The NuGet package version being added out-of-the-box are v5.x for the Xamarin packages, v2.x for the Xamarin Toolkit packages, v1.x for the Xamarin.Essentials package, and v8.x for the MVVM Toolkit package. The latest stable version.*

|Item|Template Name|
|:---:|:---:|
Expand Down Expand Up @@ -94,18 +97,18 @@ dotnet new formsclasslib -o MyApp.Core -f netstandard2.1
Option to include NuGet packages:

```shell
dotnet new formsclasslib -o MyApp.UI -it -im -ie -iei -imt -ist
dotnet new formsclasslib -o MyApp.UI -it -im -ie -iei -imt -inm -ist
```

In a single parameter (Essentials Interfaces is an exception, to be explicitly mentioned):
In a single parameter (Maps and Essentials Interfaces are exceptions, to be explicitly mentioned):

```shell
dotnet new formsclasslib -o MyApp.UI -asp -iei
dotnet new formsclasslib -o MyApp.UI -asp -iei -inm
```

NuGet Central Package Management (CPM) feature:

_For now, this is supported only on CLI. Can be used in combination with other parameters too._
*This can be used in combination with other parameters too.*

```shell
dotnet new formsclasslib -o MyApp.UI -cpm
Expand All @@ -125,7 +128,7 @@ And `-na` denotes the namespace under which the file is to be created (Can also

![Xamarin.Forms Generic Item Templates by Vijay Anand E G](images/xamarin-forms-add-new-item.png)

* A revolutionary generic item template, in XAML and C#, for creating items of any type
* An innovative generic item template, in XAML and C#, for creating items of any type
* Supported both within the VS2022 IDE and CLI
* On CLI, it is named as `forms-item` and `forms-item-cs`
* The same set of parameters is defined in the UI as `Dropdown`, `TextBox` and `CheckBox` for ease of use
Expand All @@ -142,9 +145,12 @@ And `-na` denotes the namespace under which the file is to be created (Can also

*Tip 1: For XAML template, pass the `xmlns` scope, like `xct:Popup`, as part of the input parameter value and it'll be used appropriately in the generated source files.*

*Tip: Tip: Use `local` scope to refer to the types in the same directory like `Views`. For e.g., `local:BasePage`.*
*Tip: Tip: Use `local` scope (a predefined scope in the template) to refer to the types in the same directory like `Views`. For e.g., `local:BasePage`.*

Example:

*Suffixes like Page, View, and so on are necessary while using generic item templates.*

```shell
dotnet new forms-item -n ThemePopup -b xct:Popup -p:na MyApp.Views
```
Expand Down Expand Up @@ -202,36 +208,36 @@ Views

**Page:**
```shell
dotnet new forms-page -n Login -na MyApp.Views
dotnet new forms-page -n Login -p:na MyApp.Views
```
```shell
dotnet new forms-page-cs -n Home -na MyApp.Views
dotnet new forms-page-cs -n Home -p:na MyApp.Views
```

**View:**
```shell
dotnet new forms-view -n Card -na MyApp.Views
dotnet new forms-view -n Card -p:na MyApp.Views
```
```shell
dotnet new forms-view-cs -n Order -na MyApp.Views
dotnet new forms-view-cs -n Order -p:na MyApp.Views
```

**Shell:**
```shell
dotnet new forms-shell -n App -na MyApp
dotnet new forms-shell -n App -p:na MyApp
```
```shell
dotnet new forms-shell-cs -n Mobile -na MyApp
dotnet new forms-shell-cs -n Mobile -p:na MyApp
```

**Resource Dictionary:**

With C# code-behind file:
```shell
dotnet new forms-resdict -n DefaultTheme -na MyApp.Themes
dotnet new forms-resdict -n DefaultTheme -p:na MyApp.Themes
```

Without C# code-behind file - Xaml only (The option to be specified is `-xo` or `--xaml-only`):
```shell
dotnet new forms-resdict -n DarkTheme -na MyApp.Themes -xo
dotnet new forms-resdict -n DarkTheme -p:na MyApp.Themes -xo
```
Binary file modified images/xamarin-forms-class-library-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 17 additions & 9 deletions src/FormsTemplatesCLI/FormsClassLib/.template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
"$schema": "http://json.schemastore.org/vs-2017.3.host",
"icon": "ide/icon.png",
"symbolInfo": [
{
"id": "central-pkg-mgmt",
"name": {
"text": "Use _NuGet Central Package Management (CPM)"
},
"isVisible": true,
"defaultValue": "false"
},
{
"id": "all-supported-packages",
"name": {
"text": "_Add all supported NuGet package reference (Essentials Interfaces is explicit)"
"text": "_Add all supported NuGet package reference (Maps and Essentials Interfaces are explicit)"
},
"isVisible": true,
"defaultValue": "false"
Expand Down Expand Up @@ -35,33 +43,33 @@
"defaultValue": "false"
},
{
"id": "include-essentials-interfaces",
"id": "include-mvvm-toolkit",
"name": {
"text": "Add Xamarin.Essentials._Interfaces NuGet package reference"
"text": "Add CommunityToolkit.Mvvm (aka Microsoft MV_VM Toolkit) NuGet package reference"
},
"isVisible": true,
"defaultValue": "false"
},
{
"id": "include-mvvm-toolkit",
"id": "include-shared-toolkit",
"name": {
"text": "Add CommunityToolkit.Mvvm (aka Microsoft MV_VM Toolkit) NuGet package reference"
"text": "Add VijayAnand.Toolkit.Markup (aka _Shared Toolkit) NuGet package reference"
},
"isVisible": true,
"defaultValue": "false"
},
{
"id": "include-shared-toolkit",
"id": "include-maps",
"name": {
"text": "Add and configure VijayAnand.Toolkit.Markup (_Shared Toolkit) NuGet package reference"
"text": "Add Xamarin.Forms.Maps NuGet package reference"
},
"isVisible": true,
"defaultValue": "false"
},
{
"id": "central-pkg-mgmt",
"id": "include-essentials-interfaces",
"name": {
"text": "Use _NuGet Central Package Management (CPM)"
"text": "Add Xamarin.Essentials._Interfaces NuGet package reference"
},
"isVisible": true,
"defaultValue": "false"
Expand Down
42 changes: 29 additions & 13 deletions src/FormsTemplatesCLI/FormsClassLib/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,63 @@
"datatype": "bool",
"defaultValue": "false",
"description": "Option to configure NuGet Central Package Management (CPM).",
"displayName": "Option to configure _NuGet Central Package Management (CPM)"
"displayName": "Use _NuGet Central Package Management (CPM)"
},
"all-supported-packages": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Option to add all supported NuGet package reference (Essentials Interfaces is explicit).",
"displayName": "_Add all supported NuGet package reference"
"description": "Option to add all supported NuGet package reference (Maps and Essentials Interfaces are explicit).",
"displayName": "_Add all supported NuGet package reference (Maps and Essentials Interfaces are explicit)"
},
"include-toolkit": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.CommunityToolkit NuGet package."
"description": "If true, includes reference to the Xamarin.CommunityToolkit NuGet package.",
"displayName": "Add Xamarin.Community_Toolkit NuGet package reference"
},
"include-markup": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.CommunityToolkit.Markup NuGet package."
"description": "If true, includes reference to the Xamarin.CommunityToolkit.Markup NuGet package.",
"displayName": "Add Xamarin.CommunityToolkit._Markup NuGet package reference"
},
"include-essentials": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.Essentials NuGet package."
"description": "If true, includes reference to the Xamarin.Essentials NuGet package.",
"displayName": "Add Xamarin._Essentials NuGet package reference"
},
"include-essentials-interfaces": {
"include-mvvm-toolkit": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.Essentials.Interfaces NuGet package."
"description": "If true, includes reference to the CommunityToolkit.Mvvm (aka Microsoft MVVM Toolkit) NuGet package.",
"displayName": "Add CommunityToolkit.Mvvm (aka Microsoft MV_VM Toolkit) NuGet package reference"
},
"include-mvvm-toolkit": {
"include-shared-toolkit": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the CommunityToolkit.Mvvm (aka Microsoft MVVM Toolkit) NuGet package."
"description": "Option to add VijayAnand.Toolkit.Markup (aka Shared Toolkit) NuGet package reference.",
"displayName": "Add VijayAnand.Toolkit.Markup (aka _Shared Toolkit) NuGet package reference"
},
"include-shared-toolkit": {
"include-maps": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.Forms.Maps NuGet package.",
"displayName": "Add Xamarin.Forms.Maps NuGet package reference"
},
"include-essentials-interfaces": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Option to add VijayAnand.Toolkit.Markup (Shared Toolkit) NuGet package reference.",
"displayName": "Add VijayAnand.Toolkit.Markup NuGet package reference"
"description": "If true, includes reference to the Xamarin.Essentials.Interfaces NuGet package.",
"displayName": "Add Xamarin.Essentials._Interfaces NuGet package reference"
},
"Preview": {
"type": "parameter",
Expand Down Expand Up @@ -125,6 +137,10 @@
"type": "computed",
"value": "(include-essentials-interfaces)"
},
"AddMaps": {
"type": "computed",
"value": "(include-maps)"
},
"AddMvvmToolkit": {
"type": "computed",
"value": "(include-mvvm-toolkit || all-supported-packages)"
Expand Down
3 changes: 3 additions & 0 deletions src/FormsTemplatesCLI/FormsClassLib/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Xamarin.Forms" Version="5.0.0.2662" />
<!--#if (AddMaps)-->
<PackageVersion Include="Xamarin.Forms.Maps" Version="5.0.0.2662" />
<!--#endif-->
<!--#if (AddEssentials)-->
<PackageVersion Include="Xamarin.Essentials" Version="1.8.1" />
<!--#endif-->
Expand Down
6 changes: 6 additions & 0 deletions src/FormsTemplatesCLI/FormsClassLib/FormsClassLib.1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<ItemGroup>
<!--#if (CentralPkgMgmt)-->
<PackageReference Include="Xamarin.Forms" />
<!--#if (AddMaps)-->
<PackageReference Include="Xamarin.Forms.Maps" />
<!--#endif-->
<!--#if (AddToolkit)-->
<PackageReference Include="Xamarin.CommunityToolkit" />
<!--#endif-->
Expand All @@ -42,6 +45,9 @@
<!--#endif-->
<!--#else-->
<PackageReference Include="Xamarin.Forms" Version="5.*" />
<!--#if (AddMaps)-->
<PackageReference Include="Xamarin.Forms.Maps" Version="5.*" />
<!--#endif-->
<!--#if (AddToolkit)-->
<PackageReference Include="Xamarin.CommunityToolkit" Version="2.*" />
<!--#endif-->
Expand Down
4 changes: 4 additions & 0 deletions src/FormsTemplatesCLI/FormsClassLib/HomePage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
#if AddMaps

using Xamarin.Forms.Maps;
#endif
#if (AddEssentials || AddEssentialsInterfaces)

using Xamarin.Essentials;
Expand Down
14 changes: 14 additions & 0 deletions src/FormsTemplatesCLI/FormsItem/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,27 @@
"XamlOnly": {
"type": "computed",
"value": "(xaml-only)"
},
"Xmlns": {
"type": "derived",
"valueSource": "base",
"valueTransform": "Scope"
},
"Toolkit": {
"type": "computed",
"value": "(Xmlns == \"xct\")"
}
},
"forms": {
"ValueWithoutScope": {
"identifier": "replace",
"pattern": "^.*\\:(?=[^\\:]+$)",
"replacement": ""
},
"Scope": {
"identifier": "replace",
"pattern": "\\:?\\w+$",
"replacement": ""
}
},
"sources": [
Expand Down
12 changes: 12 additions & 0 deletions src/FormsTemplatesCLI/FormsItem/FormsItem.1.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
<!--#if (Toolkit)-->
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
<!--#endif-->
xmlns:local="clr-namespace:MyApp.Namespace"
x:TypeArguments="TObject"
mc:Ignorable="d">
Expand All @@ -17,6 +20,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
<!--#if (Toolkit)-->
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
<!--#endif-->
xmlns:local="clr-namespace:MyApp.Namespace"
mc:Ignorable="d">
</ContentPage>
Expand All @@ -29,6 +35,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
<!--#if (Toolkit)-->
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
<!--#endif-->
xmlns:local="clr-namespace:MyApp.Namespace"
x:TypeArguments="TObject"
mc:Ignorable="d">
Expand All @@ -40,6 +49,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
<!--#if (Toolkit)-->
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
<!--#endif-->
xmlns:local="clr-namespace:MyApp.Namespace"
mc:Ignorable="d">
</ContentPage>
Expand Down
4 changes: 4 additions & 0 deletions src/FormsTemplatesCLI/FormsItem/FormsItem.1.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
#if Toolkit

using Xamarin.CommunityToolkit.UI.Views;
#endif

namespace MyApp.Namespace
{
Expand Down
Loading

0 comments on commit 3055465

Please sign in to comment.