Skip to content

Instantly share code, notes, and snippets.

View dhindrik's full-sized avatar
😎
Writing code!

Daniel Hindrikes dhindrik

😎
Writing code!
View GitHub Profile
#nullable enable
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Shapes;
namespace ShapeDemo.Controls
{
public class RatingControl : StackLayout
{
public partial class MainPage : ContentPage
{
private MainPageViewModel ViewModel => BindingContext as MainPageViewModel;
public MainPage(MainPageViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
// Option 1
foreach (var viewModel in assembly.DefinedTypes.Where(e => e.IsSubclassOf(typeof(ViewModel))))
{
builder.Services.AddTransient(viewModel.GetType());
}
foreach (var view in assembly.DefinedTypes.Where(e => e.IsSubclassOf(typeof(Views.View))))
{
builder.Services.AddTransient(view.GetType());
}
public class MyViewModel : ViewModelBase
{
public event EventHandler DataUpdated
public override Task Initialize()
{
//Subscribe to event when ViewModel in initialized.
DataUpdated += Data_DataUpdated;
}
<mvvm:TinyApplication xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:windows="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;assembly=Microsoft.Maui.Controls"
xmlns:local="clr-namespace:MauiSample"
xmlns:mvvm="clr-namespace:TinyMvvm.Maui;assembly=TinyMvvm.Maui"
x:Class="MauiSample.App"
windows:Application.ImageDirectory="Assets">
<Application.Resources>
<ResourceDictionary>
<CarouselView ItemSource="{Binding Persons, Mode=OneTime}">
<CarouselView.ItemTemplate>
<DataTemplate x:DataType="models:Person">
<Grid RowDefinitions="*, 30">
<Image Source="{Binding Photo, Mode=OneTime}" />
<Label Grid.Row="1" Text="{Binding Name Mode=OneTime}" />
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
public List<Person> {get; set;} = new List<Person>()
{
new Person() {Name = "Daniel Hindrikes", Photo="daniel.png"},
new Person() {Name = "Satya Nadella", Photo="satya.png"}
};
<Button Text="Create" Command="{Binding Create, Mode=OneTime}" />
public ICommand Create => new TinyCommand(async() => {
await CreatePerson();
});
<CollectionView ItemSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Person">
<StackLayout>
<Label Text="{Binding Name, Mode=OneTime}" />
<Label Text="{Binding Email, Mode=OneTime}" />
<label Text="{Binding Count}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>