Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created October 12, 2023 04:16
Show Gist options
  • Save brianmed/7fd5fcf154cb7ae4cfbf3e772bb8141d to your computer and use it in GitHub Desktop.
Save brianmed/7fd5fcf154cb7ae4cfbf3e772bb8141d to your computer and use it in GitHub Desktop.
Main XAML:
<TableView Intent="Data" HasUnevenRows="true">
<TableRoot>
<TableSection
Title="Images"
x:Name="ImagesTableSection">
</TableSection>
</TableRoot>
Code behind:
public record MixPhotoListItem(ImageSource ImageSource, Thickness CellBorderThickness);
this.ImagesTableSection.Add(new MixProfileViewCell(new MixPhotoListItem(ImageSource.FromFile(imagePath), new Thickness(12)));
MixProfileViewCell.xaml:
<ViewCell
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
x:Class="StreamHQ.MixProfileViewCell">
<telerik:RadBorder
Grid.Row="0"
Grid.Column="0"
Grid.RowSpan="2"
BorderThickness="{Binding CellBorderThickness}"
BorderColor="#F0F4F8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image
Grid.Row="0"
Grid.Column="0"
Grid.RowSpan="2"
HeightRequest="76"
HorizontalOptions="Center"
Margin="8"
Source="{Binding ImageSource}"
VerticalOptions="Center"
WidthRequest="76">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTappedImage" />
</Image.GestureRecognizers>
</Image>
</Grid>
</telerik:RadBorder>
</ViewCell>
MixProfileViewViewCell.xaml.cs
namespace StreamHQ;
public partial class MixProfileViewCell : ViewCell
{
// ImageSource
public static readonly BindableProperty ImageSourceProperty =
BindableProperty.Create("ImageSource", typeof(ImageSource), typeof(MixProfileViewCell), null);
public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
}
// CellBorderThickness
public static readonly BindableProperty CellBorderThicknessProperty =
BindableProperty.Create("CellBorderThickness", typeof(Thickness), typeof(MixProfileViewCell), new Thickness());
public Thickness CellBorderThickness
{
get { return (Thickness)GetValue(CellBorderThicknessProperty); }
set { SetValue(CellBorderThicknessProperty, value); }
}
public MixProfileViewCell(MixPhotoListItem item)
{
this.InitializeComponent();
this.BindingContext = item;
this.Appearing += OnAppearing;
this.Disappearing += OnDisappearing;
}
~MixProfileViewCell()
{
this.Appearing -= OnAppearing;
this.Disappearing -= OnDisappearing;
}
private void OnAppearing(object sender, EventArgs args)
{
this.Tapped += OnTapped;
}
private void OnDisappearing(object sender, EventArgs args)
{
this.Tapped -= OnTapped;
}
private async void OnTapped(object sender, EventArgs args)
{
await this.DisplayAlert("Info", "Tapped", "Ok");
}
private async void OnTappedImage(object sender, EventArgs args)
{
await this.DisplayAlert("Info", "Tapped", "Ok");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment