🧪 custom view

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

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

@ -58,12 +58,22 @@ public partial class MainPage : ContentPage
} }
public ICommand MyNextCommand { get; set; } public ICommand MyNextCommand { get; set; }
public ICommand MyInfoCommand { get; set; }
public ICommand MyTapCommand { get; set; }
private void InitCommands() private void InitCommands()
{ {
MyNextCommand = new Command<object>( MyNextCommand = new Command<object>(
str => DisplayAlert("Next2", $"This view is related to {str}", "Ok") 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" <Grid Margin="0,0,0,4"
BindingContext="{x:Reference root}"> BindingContext="{x:Reference root}">
<Grid.GestureRecognizers> <Grid.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped"/> <TapGestureRecognizer
Tapped="OnTapped"
Command="{Binding TapCommand, Source={x:Reference root}}"
CommandParameter="{Binding TapCommandParameter, Source={x:Reference root}}"
/>
</Grid.GestureRecognizers> </Grid.GestureRecognizers>
<Border Stroke="{Binding Color}" StrokeThickness="4" <Border Stroke="{Binding Color}" StrokeThickness="4"
Margin="0, 2" Padding="8,4"> Margin="0, 2" Padding="8,4">
@ -35,7 +39,9 @@
WidthRequest="28" MinimumWidthRequest="20" WidthRequest="28" MinimumWidthRequest="20"
HeightRequest="28" MinimumHeightRequest="20" HeightRequest="28" MinimumHeightRequest="20"
Grid.Column="2" Grid.RowSpan="2" Grid.Column="2" Grid.RowSpan="2"
Clicked="OnInfoClicked"> Clicked="OnInfoClicked"
Command="{Binding InfoCommand}"
CommandParameter="{Binding InfoCommandParameter}">
<ImageButton.Behaviors> <ImageButton.Behaviors>
<toolkit:IconTintColorBehavior <toolkit:IconTintColorBehavior
TintColor="{AppThemeBinding Light=Black, Dark=White}"/> TintColor="{AppThemeBinding Light=Black, Dark=White}"/>

@ -82,4 +82,40 @@ public partial class MyAvatarView : ContentView
get => GetValue(NextCommandParameterProperty); get => GetValue(NextCommandParameterProperty);
set => SetValue(NextCommandParameterProperty, value); 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