2017-09-21 1 views
0

Hallo Wie kann ich erweitern in die Schaltfläche für eine benutzerdefinierte Lösung anzeigen?So erweitern Sie die Schaltfläche für eine benutzerdefinierte Lösung Xamarin

Ich werde nicht diese erweitern:

....

<Button BackgroundColor="#388fee" BorderColor="#388fee" BorderRadius="25" WidthRequest="50" HeightRequest="50" 
       Command="{Binding CheckinShareCommand}" Margin="0,16"> 
      <Button.Image> 
       <FileImageSource File="googlemap_view_share_button.png" /> 
      </Button.Image> 
     </Button> 

....

Dies ist meine individuelle Lösung.

Wenn Sie ein Bild und drücken es verklärt ihn

public class CustomImage: Bild { public static Nur-Lese-BindableProperty Command = BindableProperty.Create (p => p.Command, null); öffentlicher ICommand-Befehl { get {return (ICommand) GetValue (CommandProperty); } set {SetValue (CommandProperty, Wert); }}

public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<CustomImage, object>(p => p.CommandParameter, null); 
    public object CommandParameter 
    { 
     get { return (object)GetValue(CommandParameterProperty); } 
     set { SetValue(CommandParameterProperty, value); } 
    } 

    private ICommand TransitionCommand 
    { 
     get 
     { 
      return new Command(async() => 
      { 
       this.AnchorX = 0.48; 
       this.AnchorY = 0.48; 
       await this.ScaleTo(2.8, 50, Easing.Linear); 
       await Task.Delay(100); 
       await this.ScaleTo(1, 50, Easing.Linear); 
       if (Command != null) 
       { 
        Command.Execute(CommandParameter); 
       } 
      }); 
     } 
    } 

    public CustomImage() 
    { 
     Initialize(); 
    } 


    public void Initialize() 
    { 
     GestureRecognizers.Add(new TapGestureRecognizer() 
     { 
      Command = TransitionCommand 
     }); 

....

+0

Sind Sie wollen Vergrößerungen auf Ihre Schaltfläche drücken? –

+0

ja, wenn ich den Knopf drücke ich möchte Vergrößerungen Effekt –

+0

Schau dir meine Antwort hoffe es hilft dir !!! –

Antwort

1

Wenn Sie vergrößert Bild, wenn Sie darauf drücken Versuchen Below-Code:

public class CustomButton : Button 
{ 
    public CustomButton() : base() 
    { 
     const int _animationTime = 10; 
     Clicked += async (sender, e) => 
     { 
      try 
      { 
       var btn = (CustomButton)sender; 
       await btn.ScaleTo(1.2, _animationTime); 
       await btn.ScaleTo(1, _animationTime); 
      } 
      catch (Exception ex) 
      { 
       ex.Track(); 
      } 
     }; 

    } 
} 

XAML

<userControls:CustomButton BackgroundColor="#388fee" BorderColor="#388fee" BorderRadius="25" WidthRequest="50" HeightRequest="50" 
       Command="{Binding CheckinShareCommand}" Margin="0,16"> 
      <Button.Image> 
       <FileImageSource File="googlemap_view_share_button.png" /> 
      </Button.Image> 
     </userControls:CustomButton> 

Vergessen Sie nicht, dies zu setzen ie in header

xmlns:userControls="clr-namespace:YourNameSpace.UserControls" 
Verwandte Themen