From 450ef3aace6a4a28e795857792f5c4a656d9c5ba Mon Sep 17 00:00:00 2001 From: marcchevaldonne Date: Wed, 1 May 2024 23:23:19 +0200 Subject: [PATCH] :test_tube: custom view --- .../ex_CustomContentView/MainPage.xaml | 20 +++++++++-- .../ex_CustomContentView/MainPage.xaml.cs | 10 ++++++ .../ex_CustomContentView/MyAvatarView.xaml | 10 ++++-- .../ex_CustomContentView/MyAvatarView.xaml.cs | 36 +++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/ch03_DataBinding/ex_CustomContentView/MainPage.xaml b/ch03_DataBinding/ex_CustomContentView/MainPage.xaml index 950169b..d299c70 100644 --- a/ch03_DataBinding/ex_CustomContentView/MainPage.xaml +++ b/ch03_DataBinding/ex_CustomContentView/MainPage.xaml @@ -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"/> + Tapped="OnTapped" + TapCommand="{Binding MyTapCommand}" + TapCommandParameter="{Binding Source={RelativeSource Self}}" + InfoCommand="{Binding MyInfoCommand}" + InfoCommandParameter="{Binding Artist2}" + NextCommand="{Binding MyNextCommand}" + NextCommandParameter="R.Rinaudo"/> + Tapped="OnTapped" + TapCommand="{Binding MyTapCommand}" + TapCommandParameter="{Binding Source={RelativeSource Self}}" + InfoCommand="{Binding MyInfoCommand}" + InfoCommandParameter="{Binding Artist3}" + NextCommand="{Binding MyNextCommand}" + NextCommandParameter="B.Lafuente"/> diff --git a/ch03_DataBinding/ex_CustomContentView/MainPage.xaml.cs b/ch03_DataBinding/ex_CustomContentView/MainPage.xaml.cs index ea45644..659f1dc 100644 --- a/ch03_DataBinding/ex_CustomContentView/MainPage.xaml.cs +++ b/ch03_DataBinding/ex_CustomContentView/MainPage.xaml.cs @@ -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( str => DisplayAlert("Next2", $"This view is related to {str}", "Ok") ); + + MyInfoCommand = new Command( + artist => DisplayAlert("Info2", $"This view is related to {artist.Name}", "Ok") + ); + + MyTapCommand = new Command( + av => DisplayAlert("Tap", $"This view is related to {av.Title}", "Ok") + ); } } diff --git a/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml b/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml index 62e8ffd..eb55f94 100644 --- a/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml +++ b/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml @@ -7,7 +7,11 @@ - + @@ -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}"> diff --git a/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml.cs b/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml.cs index 2f7ad89..ab2e44f 100644 --- a/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml.cs +++ b/ch03_DataBinding/ex_CustomContentView/MyAvatarView.xaml.cs @@ -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); + } } \ No newline at end of file