🧪 custom view

pull/5/head
Marc CHEVALDONNE 1 year ago
parent 72a3b602fd
commit 450ef3aace

@ -15,6 +15,10 @@
InfoClicked="OnInfoClicked"
NextClicked="OnNextClicked"
Tapped="OnTapped"
TapCommand="{Binding MyTapCommand}"
TapCommandParameter="{Binding Source={RelativeSource Self}}"
InfoCommand="{Binding MyInfoCommand}"
InfoCommandParameter="{Binding Artist1}"
NextCommand="{Binding MyNextCommand}"
NextCommandParameter="D.Joussein"/>
<local:MyAvatarView
@ -24,7 +28,13 @@
Color="{Binding MainColor}"
InfoClicked="OnInfoClicked"
NextClicked="OnNextClicked"
Tapped="OnTapped"/>
Tapped="OnTapped"
TapCommand="{Binding MyTapCommand}"
TapCommandParameter="{Binding Source={RelativeSource Self}}"
InfoCommand="{Binding MyInfoCommand}"
InfoCommandParameter="{Binding Artist2}"
NextCommand="{Binding MyNextCommand}"
NextCommandParameter="R.Rinaudo"/>
<local:MyAvatarView
ImageName="{Binding Artist3.Picture}"
Title="{Binding Artist3.Name}"
@ -32,7 +42,13 @@
Color="{Binding MainColor}"
InfoClicked="OnInfoClicked"
NextClicked="OnNextClicked"
Tapped="OnTapped"/>
Tapped="OnTapped"
TapCommand="{Binding MyTapCommand}"
TapCommandParameter="{Binding Source={RelativeSource Self}}"
InfoCommand="{Binding MyInfoCommand}"
InfoCommandParameter="{Binding Artist3}"
NextCommand="{Binding MyNextCommand}"
NextCommandParameter="B.Lafuente"/>
<Image Source="nout_live_album.png" WidthRequest="100"/>
</VerticalStackLayout>
</ContentPage>

@ -58,12 +58,22 @@ public partial class MainPage : ContentPage
}
public ICommand MyNextCommand { get; set; }
public ICommand MyInfoCommand { get; set; }
public ICommand MyTapCommand { get; set; }
private void InitCommands()
{
MyNextCommand = new Command<object>(
str => DisplayAlert("Next2", $"This view is related to {str}", "Ok")
);
MyInfoCommand = new Command<Artist>(
artist => DisplayAlert("Info2", $"This view is related to {artist.Name}", "Ok")
);
MyTapCommand = new Command<MyAvatarView>(
av => DisplayAlert("Tap", $"This view is related to {av.Title}", "Ok")
);
}
}

@ -7,7 +7,11 @@
<Grid Margin="0,0,0,4"
BindingContext="{x:Reference root}">
<Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped"/>
<TapGestureRecognizer
Tapped="OnTapped"
Command="{Binding TapCommand, Source={x:Reference root}}"
CommandParameter="{Binding TapCommandParameter, Source={x:Reference root}}"
/>
</Grid.GestureRecognizers>
<Border Stroke="{Binding Color}" StrokeThickness="4"
Margin="0, 2" Padding="8,4">
@ -35,7 +39,9 @@
WidthRequest="28" MinimumWidthRequest="20"
HeightRequest="28" MinimumHeightRequest="20"
Grid.Column="2" Grid.RowSpan="2"
Clicked="OnInfoClicked">
Clicked="OnInfoClicked"
Command="{Binding InfoCommand}"
CommandParameter="{Binding InfoCommandParameter}">
<ImageButton.Behaviors>
<toolkit:IconTintColorBehavior
TintColor="{AppThemeBinding Light=Black, Dark=White}"/>

@ -82,4 +82,40 @@ public partial class MyAvatarView : ContentView
get => GetValue(NextCommandParameterProperty);
set => SetValue(NextCommandParameterProperty, value);
}
public static readonly BindableProperty InfoCommandProperty =
BindableProperty.Create("InfoCommand", typeof(ICommand), typeof(MyAvatarView), null);
public ICommand InfoCommand
{
get => (ICommand)GetValue(InfoCommandProperty);
set => SetValue(InfoCommandProperty, value);
}
public static readonly BindableProperty InfoCommandParameterProperty =
BindableProperty.Create("InfoCommandParameter", typeof(object), typeof(MyAvatarView), null);
public object InfoCommandParameter
{
get => GetValue(InfoCommandParameterProperty);
set => SetValue(InfoCommandParameterProperty, value);
}
public static readonly BindableProperty TapCommandProperty =
BindableProperty.Create("TapCommand", typeof(ICommand), typeof(MyAvatarView), null);
public ICommand TapCommand
{
get => (ICommand)GetValue(TapCommandProperty);
set => SetValue(TapCommandProperty, value);
}
public static readonly BindableProperty TapCommandParameterProperty =
BindableProperty.Create("TapCommandParameter", typeof(object), typeof(MyAvatarView), null);
public object TapCommandParameter
{
get => GetValue(TapCommandParameterProperty);
set => SetValue(TapCommandParameterProperty, value);
}
}
Loading…
Cancel
Save