diff options
Diffstat (limited to 'Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs')
-rw-r--r-- | Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs b/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs new file mode 100644 index 00000000..bb276014 --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/ButtonGallery.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Forms.Controls +{ + public class ButtonGallery : ContentPage + { + public ButtonGallery () + { + BackgroundColor = new Color (0.9); + + var normal = new Button { Text = "Normal Button" }; + normal.Effects.Add (Effect.Resolve ("XamControl.BorderEffect")); + + var disabled = new Button { Text = "Disabled Button"}; + var disabledswitch = new Switch (); + disabledswitch.SetBinding (Switch.IsToggledProperty, "IsEnabled"); + disabledswitch.BindingContext = disabled; + + var canTapLabel = new Label { + Text = "Cannot Tap" + }; + + disabled.Clicked += (sender, e) => { + canTapLabel.Text = "TAPPED!"; + }; + + var click = new Button { Text = "Click Button" }; + var rotate = new Button { Text = "Rotate Button" }; + var transparent = new Button { Text = "Transparent Button" }; + + var fontName = Device.OnPlatform ("Georgia", "sans-serif-light", "Comic Sans MS"); + var font = Font.OfSize (fontName, NamedSize.Medium); + + var themedButton = new Button { + Text = "Accent Button", + BackgroundColor = Color.Accent, + TextColor = Color.White, + ClassId = "AccentButton", + Font = font + }; + var borderButton = new Button { + Text = "Border Button", + BorderColor = Color.Black, + BackgroundColor = Color.Purple, + BorderWidth = 5, + BorderRadius = 5 + }; + var timer = new Button { Text = "Timer" }; + var busy = new Button { Text = "Toggle Busy" }; + var alert = new Button { Text = "Alert" }; + var alertSingle = new Button {Text = "Alert Single"}; + var image = new Button { Text = "Image Button", Image = new FileImageSource {File = "bank.png"}, BackgroundColor = Color.Blue.WithLuminosity (.8) }; + + themedButton.Clicked += (sender, args) => themedButton.Font = Font.Default; + + alertSingle.Clicked += (sender, args) => DisplayAlert ("Foo", "Bar", "Cancel"); + + disabled.IsEnabled = false; + int i = 1; + click.Clicked += (sender, e) => { click.Text = "Clicked " + i++; }; + rotate.Clicked += (sender, e) => rotate.RelRotateTo (180); + transparent.Opacity = .5; + + int j = 1; + timer.Clicked += (sender, args) => Device.StartTimer (TimeSpan.FromSeconds (1), () => { + timer.Text = "Timer Elapsed " + j++; + return j < 4; + }); + + bool isBusy = false; + busy.Clicked += (sender, args) => IsBusy = isBusy = !isBusy; + + alert.Clicked += async (sender, args) => { + var result = await DisplayAlert ("User Alert", "This is a user alert. This is only a user alert.", "Accept", "Cancel"); + alert.Text = result ? "Accepted" : "Cancelled"; + }; + + borderButton.Clicked += (sender, args) => borderButton.BackgroundColor = Color.Default; + + Content = new ScrollView { + Content = new StackLayout { + Padding = new Size (20, 20), + Children = { + normal, + new StackLayout { + Orientation = StackOrientation.Horizontal, + Children={ + disabled, + disabledswitch, + }, + }, + canTapLabel, + click, + rotate, + transparent, + themedButton, + borderButton, + new Button {Text = "Thin Border", BorderWidth = 1, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black}, + new Button {Text = "Thinner Border", BorderWidth = .5, BackgroundColor=Color.White, BorderColor = Color.Black, TextColor = Color.Black}, + timer, + busy, + alert, + alertSingle, + image, + } + } + }; + + } + } +} |