Skip to content

Instantly share code, notes, and snippets.

TeamMatesViewModel.cs
public readonly SQLiteConnection conn;
...
public TeamMatesViewModel()
{
...
conn = new SQLiteConnection($@"{FileSystem.AppDataDirectory}/teammates.db3");
TeamMateSquad = new ObservableCollection<TeamMateItem>(conn.Table<TeamMateItem>().ToList());
}
<CollectionView ItemsSource="{Binding TeamMateSquad}">
<CollectionView.ItemTemplate>
<DataTemplate>
<in2teamssplitter:NameAndRating Name="{Binding Name, Mode=TwoWay}" Level="{Binding Level}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
TeamMateSquad = new ObservableCollection<TeamMateItem>(new List<TeamMateItem>()
{
new TeamMateItem()
{
Name = "First TeamMate",
Level = 0
},
new TeamMateItem()
{
Name = "Second TeamMate",
class TeamMateItem : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetPropertyValue<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (Equals(field, value)) return false;
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<Entry Grid.Column="0" Text="{Binding Name, Source={x:Reference _nameAndRate}}" HorizontalOptions="FillAndExpand" />
<ffsvg:SvgCachedImage Grid.Column="1" Source="{Binding Level, Source={x:Reference _nameAndRate}, Converter={StaticResource SVGStatusConverter}, ConverterParameter = 1}" />
<ffsvg:SvgCachedImage Grid.Column="2" Source="{Binding Level, Source={x:Reference _nameAndRate}, Converter={StaticResource SVGStatusConverter}, ConverterParameter = 2}" />
<ffsvg:SvgCachedImage Grid.Column="3" Source="{Binding Level, Source={x:Reference _nameAndRate}, Converter={StaticResource SVGStatusConverter}, ConverterParameter = 3}" />
public static readonly BindableProperty LevelProperty = BindableProperty.Create(nameof(Level), typeof(int), typeof(NameAndRating), defaultBindingMode: BindingMode.TwoWay);
public int Level
{
get => (int)GetValue(LevelProperty);
set => SetValue(LevelProperty, value);
}
public class SVGPathConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => GetSVGName((int)(value ?? 0), int.Parse(parameter as string ?? "0"));
string GetSVGName(int status, int parameter)
{
if (status >= parameter)
return "resource://In2TeamsSplitter.Resources.starFilled.svg";
else
return "resource://In2TeamsSplitter.Resources.starEmpty.svg";
Forms.SetFlags("CollectionView_Experimental");
<?xml version="1.0" encoding="utf-8" ?>
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
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"
mc:Ignorable="d"
x:Name="_nameAndRate"
x:Class="In2TeamsSplitter.NameAndRating">
<Entry Text="{Binding Name, Source={x:Reference _nameAndRate}}" HorizontalOptions="FillAndExpand" />
</Grid>
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class NameAndRating : Grid
{
public NameAndRating()
{
InitializeComponent();
}
public static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(NameAndRating), defaultBindingMode: BindingMode.TwoWay);