Icons finally working with pngs (SVGs later maybe)
This commit is contained in:
		
							
								
								
									
										11
									
								
								Aurora/Design/Components/ImageButton/ImageButton.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Aurora/Design/Components/ImageButton/ImageButton.xaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Design.Components.ImageButton.ImageButton"> | ||||
|     <ContentView.GestureRecognizers> | ||||
|         <TapGestureRecognizer Tapped="OnButtonTapped" /> | ||||
|     </ContentView.GestureRecognizers> | ||||
|     <ContentView.Content> | ||||
|         <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"> | ||||
|             <Image x:Name="imgButton" Aspect="AspectFit" /> | ||||
|         </StackLayout> | ||||
|     </ContentView.Content> | ||||
| </ContentView> | ||||
							
								
								
									
										105
									
								
								Aurora/Design/Components/ImageButton/ImageButton.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								Aurora/Design/Components/ImageButton/ImageButton.xaml.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using Xamarin.Forms; | ||||
|  | ||||
| namespace Aurora.Design.Components.ImageButton | ||||
| { | ||||
|     public partial class ImageButton : ContentView | ||||
|     { | ||||
|         public ImageButton() | ||||
|         { | ||||
|             InitializeComponent(); | ||||
|         } | ||||
|  | ||||
|         public static readonly BindableProperty SourceProperty = | ||||
|             BindableProperty.Create( | ||||
|                 "Source", | ||||
|                 typeof(ImageSource), | ||||
|                 typeof(ImageButton), | ||||
|                 null, | ||||
|                 BindingMode.TwoWay, | ||||
|                 propertyChanged: (bindable, oldValue, newValue) => | ||||
|                 { | ||||
|                     ImageButton control = (ImageButton)bindable; | ||||
|  | ||||
|                     control.imgButton.Source = (ImageSource)newValue; | ||||
|                 }); | ||||
|  | ||||
|         public static readonly BindableProperty CommandProperty = BindableProperty.Create( | ||||
|             "Command", | ||||
|             typeof(Command), | ||||
|             typeof(ImageButton), | ||||
|             null, | ||||
|             propertyChanged: (bindable, oldValue, newValue) => | ||||
|             { | ||||
|                 ImageButton control = (ImageButton)bindable; | ||||
|                 var command = (Command)newValue; | ||||
|  | ||||
|                 CanExecute(command, control); | ||||
|  | ||||
|                 command.CanExecuteChanged += (sender, e) => | ||||
|                 { | ||||
|                     CanExecute(sender, control); | ||||
|                 }; | ||||
|             }); | ||||
|  | ||||
|         public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create( | ||||
|             "CommandParameter", | ||||
|             typeof(object), | ||||
|             typeof(ImageButton), | ||||
|             null); | ||||
|  | ||||
|         private static void CanExecute(object sender, ImageButton control) | ||||
|         { | ||||
|             var cmd = (Command)sender; | ||||
|             control.imgButton.IsEnabled = cmd.CanExecute(null); | ||||
|         } | ||||
|  | ||||
|         public ImageSource Source | ||||
|         { | ||||
|             get { return (ImageSource)GetValue(SourceProperty); } | ||||
|             set { SetValue(SourceProperty, value); } | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public event EventHandler<EventArgs> Tapped; | ||||
|  | ||||
|         public Command Command | ||||
|         { | ||||
|             get { return (Command)GetValue(CommandProperty); } | ||||
|             set { SetValue(CommandProperty, value); } | ||||
|         } | ||||
|  | ||||
|         public object CommandParameter | ||||
|         { | ||||
|             get { return GetValue(CommandParameterProperty); } | ||||
|             set { SetValue(CommandParameterProperty, value); } | ||||
|         } | ||||
|  | ||||
|         protected void OnButtonTapped(object sender, EventArgs args) | ||||
|         { | ||||
|             object resolvedParameter; | ||||
|  | ||||
|             if (CommandParameter != null) | ||||
|             { | ||||
|                 resolvedParameter = CommandParameter; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 resolvedParameter = args; | ||||
|             } | ||||
|  | ||||
|             if (Command?.CanExecute(resolvedParameter) ?? true) | ||||
|             { | ||||
|                 this.AbortAnimation("imgButtonAnim"); | ||||
|                 new Animation(v => imgButton.Scale = v, 1, 0.5).Commit(imgButton, "imgButtonAnim", 16, 150, Easing.SinOut, | ||||
|                     (v, c) => | ||||
|                     { | ||||
|                         imgButton.Scale = 1; | ||||
|                         Tapped?.Invoke(this, args); | ||||
|                         Command?.Execute(resolvedParameter); | ||||
|                     }); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user