diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Controls/ControlGalleryPages | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Controls/ControlGalleryPages')
15 files changed, 1307 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs new file mode 100644 index 00000000..0df2eeb3 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs @@ -0,0 +1,129 @@ +using System; + +using Xamarin.Forms; +using System.Diagnostics; +using System.Collections.Generic; + +namespace Xamarin.Forms.Controls +{ + public class AppearingGalleryPage : ContentPage + { + const string NavPageTitle = "NavAppearingPage"; + const string MasterPageTitle = "MasterAppearingPage"; + const string TabbedPageTitle = "TabbedAppearingPage"; + const string CarouselPageTitle = "CarouselAppearingPage"; + + public AppearingGalleryPage () + { + var initalPage = new AppearingPage (1); + var initalPage2 = new AppearingPage (2); + + Content = new StackLayout { + Children = { + new Button { Text = NavPageTitle, Command = new Command (() => { + Application.Current.MainPage = new NavAppearingPage(initalPage); + }) + }, + new Button { Text = MasterPageTitle, Command = new Command (() => { + var page = new MasterDetailPage { + Title = MasterPageTitle, + Master = new ContentPage { Title = "Master", BackgroundColor = Color.Red }, + Detail = new NavAppearingPage(initalPage) + }; + SetMainPage (page); + }) + }, + new Button { Text = TabbedPageTitle, Command = new Command (() => { + var page = new TabbedPage { + Title = TabbedPageTitle, + Children = { initalPage, initalPage2 } + }; + SetMainPage (page); + }) + }, + new Button { Text = CarouselPageTitle, Command = new Command (() => { + + var page = new CarouselPage { + Title = CarouselPageTitle, + Children = { initalPage, initalPage2 } + }; + SetMainPage (page); + }) + } + } + }; + } + + static void SetMainPage (Page page) + { + var tracker = new AppearingTracker (page); + Application.Current.MainPage = page; + } + + class AppearingTracker + { + int _isAppearingFired; + int _isDisappearingFired; + + public AppearingTracker (Page page) + { + page.Appearing += (object sender, EventArgs e) => { + _isAppearingFired++; + App.AppearingMessages.Add ($"Appearing {page.Title}"); + Debug.WriteLine ($"Appearing {page.Title}"); + }; + + page.Disappearing += (object sender, EventArgs e) => { + _isDisappearingFired++; + App.AppearingMessages.Add ($"Disappearing {page.Title}"); + Debug.WriteLine( $"Disappearing {page.Title}"); + }; + } + } + + class AppearingPage : ContentPage + { + int _theId; + ListView _listMessages; + public AppearingPage (int id) + { + var tracker = new AppearingTracker (this); + _listMessages = new ListView (); + _theId = id; + Title = $"Page {_theId}"; + Padding = new Thickness (20); + Content = new StackLayout { + Children = { + new Label { Text = $"Hello Appearing {_theId} page" }, + new Button { Text = "Push new Page", Command = new Command ( async () => { await Navigation.PushAsync( new AppearingPage(2)); }) }, + new Button { Text = "Pop page", Command = new Command ( async () => { await Navigation.PopAsync(); }) }, + new Button { Text = "Pop to root", Command = new Command ( async () => { await Navigation.PopToRootAsync(); }) }, + new Button { Text = "Change Main Page", Command = new Command ( () => { + App.AppearingMessages.Clear(); + Application.Current.MainPage = new AppearingPage(3); }) + }, + _listMessages + } + }; + } + protected override void OnAppearing () + { + base.OnAppearing (); + Device.StartTimer (new TimeSpan (200), () => { + _listMessages.ItemsSource = App.AppearingMessages; + return false; + }); + } + } + + class NavAppearingPage : NavigationPage + { + public NavAppearingPage (Page page) : base(page) + { + Title = NavPageTitle; + var tracker = new AppearingTracker (this); + } + } + } +} + diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/AutomationIDGallery.cs b/Xamarin.Forms.Controls/ControlGalleryPages/AutomationIDGallery.cs new file mode 100644 index 00000000..c93a9b69 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/AutomationIDGallery.cs @@ -0,0 +1,104 @@ +using System; + +namespace Xamarin.Forms.Controls +{ + public class AutomationIdGallery : ContentPage + { + + public AutomationIdGallery () + { + var scrollView = new ScrollView { AutomationId = "scrollMain" }; + var rootLayout = new StackLayout { AutomationId = "stckMain" }; + + var btn = new Button { + AutomationId = "btnTest1", + Text = "Test1", + Command = new Command (async () => await Navigation.PushModalAsync (new TestPage1 ())) + }; + + var btn2 = new Button { + AutomationId = "btnTest2", + Text = "Test2", + Command = new Command (async () => await Navigation.PushModalAsync (new TestPage2 ())) + }; + + rootLayout.Children.Add (btn); + rootLayout.Children.Add (btn2); + + var toolBarItem = new ToolbarItem { AutomationId = "tbItemHello", Text= "Hello", Command = new Command(async ()=> { await DisplayAlert("Hello","","ok"); }) }; + var toolBarItem2 = new ToolbarItem { AutomationId = "tbItemHello2", Order= ToolbarItemOrder.Secondary, Text= "Hello2", Command = new Command(async ()=> { await DisplayAlert("Hello2","","ok"); }) }; + + ToolbarItems.Add (toolBarItem); + ToolbarItems.Add (toolBarItem2); + + scrollView.Content = rootLayout; + Content = scrollView; + } + + internal class TestPage1 : ContentPage + { + public TestPage1 () + { + var rootLayout = new StackLayout { AutomationId = "stckMain" }; + var btn = new Button { + AutomationId = "popModal", + Text = "Pop", + Command = new Command (async () => Navigation.PopModalAsync ()) + }; + rootLayout.Children.Add (btn); + rootLayout.Children.Add (new ActivityIndicator { AutomationId = "actHello", IsRunning = true }); + rootLayout.Children.Add (new BoxView { + AutomationId = "bxvHello", + WidthRequest = 40, + HeightRequest = 40, + BackgroundColor = Color.Red + }); + rootLayout.Children.Add (new Button { AutomationId = "btnHello", Text = "Hello" }); + rootLayout.Children.Add (new DatePicker { AutomationId = "dtPicker", Date = DateTime.Parse ("01/01/2014") }); + rootLayout.Children.Add (new TimePicker { AutomationId = "tPicker", Time = new TimeSpan (14, 45, 50) }); + rootLayout.Children.Add (new Label { AutomationId = "lblHello", Text = "Hello Label" }); + rootLayout.Children.Add (new Editor { AutomationId = "editorHello", Text = "Hello Editor" }); + rootLayout.Children.Add (new Entry { AutomationId = "entryHello", Text = "Hello Entry" }); + + Content = rootLayout; + } + } + + internal class TestPage2 : ContentPage + { + public TestPage2 () + { + var rootLayout = new StackLayout { AutomationId = "stckMain" }; + var btn = new Button { + AutomationId = "popModal", + Text = "Pop", + Command = new Command (async () => Navigation.PopModalAsync ()) + }; + rootLayout.Children.Add (btn); + rootLayout.Children.Add (new Image { AutomationId = "imgHello", Source = "menuIcon" }); + rootLayout.Children.Add (new ListView { + AutomationId = "lstView", + ItemsSource = new string[2] { "one", "two" }, + HeightRequest = 50 + }); + rootLayout.Children.Add (new Picker { AutomationId = "pickerHello", Items = { "one", "two" } }); + rootLayout.Children.Add (new ProgressBar { AutomationId = "progressHello", Progress = 2 }); + rootLayout.Children.Add (new SearchBar { AutomationId = "srbHello", Text = "Hello Search" }); + rootLayout.Children.Add (new Slider { AutomationId = "sliHello", Value = 0.5 }); + rootLayout.Children.Add (new Stepper { AutomationId = "stepperHello", Value = 5 }); + rootLayout.Children.Add (new Switch { AutomationId = "switchHello" }); + rootLayout.Children.Add (new WebView { + AutomationId = "webviewHello", + WidthRequest = 100, + HeightRequest = 50, + Source = new UrlWebViewSource { Url = "http://blog.xamarin.com/" } + }); + + Content = rootLayout; + } + } + + + } +} + diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml b/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml new file mode 100644 index 00000000..accd9186 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage + xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Controls.BehaviorsAndTriggers" + xmlns:local="clr-namespace:Xamarin.Forms.Controls;assembly=Xamarin.Forms.Controls" + Padding="8"> + <StackLayout> + <Label Text="Type red in the entry below" /> + <Entry x:Name="entry" BackgroundColor="Lime"> + <Entry.Triggers> + <Trigger TargetType="Entry" Property="Text" Value="red"> + <Setter Property="Entry.BackgroundColor"> + <Color>#ff0000</Color> + </Setter> + <Trigger.EnterActions> + <local:HThrob /> + </Trigger.EnterActions> + <Trigger.ExitActions> + <local:VThrob /> + </Trigger.ExitActions> + </Trigger> + <Trigger TargetType="Entry" Property="IsFocused" Value="true"> + <Setter Property="Entry.BackgroundColor"> + <Color>#0000ff</Color> + </Setter> + </Trigger> + </Entry.Triggers> + </Entry> + <Button Text="Click me!"> + <Button.Behaviors> + <local:StopItBehavior /> + </Button.Behaviors> + </Button> + <Label BindingContext="{x:Reference entry}" Text="{Binding Path=IsFocused}" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml.cs b/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml.cs new file mode 100644 index 00000000..de9d4d2b --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/BehaviorsAndTriggers.xaml.cs @@ -0,0 +1,75 @@ +using Xamarin.Forms; +using System; + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers = true)] + public partial class BehaviorsAndTriggers : ContentPage + { + public BehaviorsAndTriggers () + { + InitializeComponent (); + } + } + + [Preserve (AllMembers = true)] + public class Throb : TriggerAction<VisualElement> + { + bool _horizontal; + + public Throb (bool horizontal) + { + _horizontal = horizontal; + } + + protected override async void Invoke (VisualElement sender) + { + for (var i=0;i<5;i++){ + await sender.TranslateTo (_horizontal ? -5:0,!_horizontal ? -5 : 0, 25); + await sender.TranslateTo (_horizontal ? 5:0,!_horizontal ? 5: 0, 25); + } + await sender.TranslateTo (0, 0, 25); + } + } + + [Preserve (AllMembers = true)] + public class HThrob : Throb + { + [Preserve] + public HThrob () + : base (true) + { + } + } + + [Preserve (AllMembers = true)] + public class VThrob : Throb + { + public VThrob () : base (false) + { + } + } + + [Preserve (AllMembers = true)] + public class StopItBehavior : Behavior<Button> + { + protected override void OnAttachedTo (Button bindable) + { + base.OnAttachedTo (bindable); + bindable.Clicked += OnClicked; + } + + protected override void OnDetachingFrom (Button bindable) + { + bindable.Clicked -= OnClicked; + base.OnDetachingFrom (bindable); + } + + void OnClicked (object sender, EventArgs e) + { + var button = (Button)sender; + button.Text = "Don't do this again"; + button.IsEnabled = false; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/CellForceUpdateSizeGalleryPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/CellForceUpdateSizeGalleryPage.cs new file mode 100644 index 00000000..35b29d48 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/CellForceUpdateSizeGalleryPage.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers = true)] + public class CellForceUpdateSizeGalleryPage : TabbedPage + { + public class ViewCellPage : ContentPage + { + [Preserve (AllMembers = true)] + public class MyViewCell : ViewCell + { + public MyViewCell () + { + var image = new Image { + Source = ImageSource.FromFile ("crimson.jpg"), + BackgroundColor = Color.Gray, + HeightRequest = 50, + VerticalOptions = LayoutOptions.Fill, + HorizontalOptions = LayoutOptions.Fill + }; + + var button = new Button { Text = "+" }; + button.Clicked += (object sender, EventArgs e) => + { + image.HeightRequest = image.Height + 100; + ForceUpdateSize (); + }; + + Tapped += (object sender, EventArgs e) => + { + image.HeightRequest = image.Height - 100; + ForceUpdateSize (); + }; + + View = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { image, button } }; + } + } + + public ViewCellPage () + { + var listview = new ListView { + HasUnevenRows = true, + }; + var items = Enumerable.Range (0, 10); + listview.ItemsSource = items; + listview.ItemTemplate = new DataTemplate (typeof (MyViewCell)); + Content = listview; + Title = "View Cell"; + } + } + + public class ImageCellPage : ContentPage + { + [Preserve (AllMembers = true)] + public class MyImageCell : ImageCell + { + public MyImageCell () + { + ImageSource = ImageSource.FromFile ("crimson.jpg"); + Height = 20; + Command = new Command (() => + { + Height += 20; + ForceUpdateSize (); + }); + } + } + public ImageCellPage () + { + var listview = new ListView { + HasUnevenRows = true, + }; + var items = Enumerable.Range (0, 10); + listview.ItemsSource = items; + listview.ItemTemplate = new DataTemplate (typeof (MyImageCell)); + Content = listview; + Title = "Image Cell"; + } + } + + public class TextCellPage : ContentPage + { + [Preserve (AllMembers = true)] + public class MyTextCell : TextCell + { + public MyTextCell () + { + Text = "I am a TextCell, short and stout."; + Height = 20; + Command = new Command (() => + { + Height += 20; + ForceUpdateSize (); + }); + } + } + + public TextCellPage () + { + var listview = new ListView { + HasUnevenRows = true, + }; + var items = Enumerable.Range (0, 10); + listview.ItemsSource = items; + listview.ItemTemplate = new DataTemplate (typeof (MyTextCell)); + Content = listview; + Title = "Text Cell"; + } + } + + public class EntryCellPage : ContentPage + { + [Preserve (AllMembers = true)] + public class MyEntryCell : EntryCell + { + public MyEntryCell () + { + Text = "I am an EntryCell, short and stout."; + Height = 20; + Tapped += (object sender, EventArgs e) => + { + Height += 20; + ForceUpdateSize (); + }; + Completed += (object sender, EventArgs e) => + { + Height -= 20; + ForceUpdateSize (); + }; + } + } + + public EntryCellPage () + { + var listview = new ListView { + HasUnevenRows = true, + }; + var items = Enumerable.Range (0, 10); + listview.ItemsSource = items; + listview.ItemTemplate = new DataTemplate (typeof (MyEntryCell)); + Content = listview; + Title = "Entry Cell"; + } + } + + public class SwitchCellPage : ContentPage + { + [Preserve (AllMembers = true)] + public class MySwitchCell : SwitchCell + { + public MySwitchCell () + { + Text = "I am a SwitchCell, short and stout."; + Height = 20; + Tapped += (object sender, EventArgs e) => + { + Height += 20; + ForceUpdateSize (); + }; + OnChanged += (object sender, ToggledEventArgs e) => + { + Height -= 20; + ForceUpdateSize (); + }; + } + } + + public SwitchCellPage () + { + var listview = new ListView { + HasUnevenRows = true, + }; + var items = Enumerable.Range (0, 10); + listview.ItemsSource = items; + listview.ItemTemplate = new DataTemplate (typeof (MySwitchCell)); + Content = listview; + Title = "Switch Cell"; + } + } + + public CellForceUpdateSizeGalleryPage () + { + Children.Add (new ViewCellPage ()); + Children.Add (new ImageCellPage ()); + Children.Add (new TextCellPage ()); + Children.Add (new EntryCellPage ()); + Children.Add (new SwitchCellPage ()); + } + } +} diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/LayoutAddPerformance.xaml b/Xamarin.Forms.Controls/ControlGalleryPages/LayoutAddPerformance.xaml new file mode 100644 index 00000000..da51089d --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/LayoutAddPerformance.xaml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8" ?> +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Controls.LayoutAddPerformance"> + <ScrollView> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Label x:Name="timingLabel" BackgroundColor="Gray" /> + <StackLayout Grid.Row="1" x:Name="layout"> + </StackLayout> + </Grid> + </ScrollView> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/LayoutAddPerformance.xaml.cs b/Xamarin.Forms.Controls/ControlGalleryPages/LayoutAddPerformance.xaml.cs new file mode 100644 index 00000000..1c25c633 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/LayoutAddPerformance.xaml.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Controls +{ + public partial class LayoutAddPerformance : ContentPage + { + public LayoutAddPerformance () + { + InitializeComponent (); + } + + protected override async void OnAppearing () + { + base.OnAppearing (); + + layout.Children.Clear (); + + await Task.Delay (2000); + + Stopwatch sw = new Stopwatch(); + sw.Start (); + for (int i = 0; i < 500; i++) { + layout.Children.Add (new Label { Text = i.ToString () }); + } + sw.Stop (); + this.timingLabel.Text = sw.ElapsedMilliseconds.ToString (); + } + } +} diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/ListRefresh.cs b/Xamarin.Forms.Controls/ControlGalleryPages/ListRefresh.cs new file mode 100644 index 00000000..28afd7be --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/ListRefresh.cs @@ -0,0 +1,115 @@ +using System; +using Xamarin.Forms; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Xamarin.Forms.Controls +{ + public class ListRefresh : ContentPage + { + public ListRefresh () + { + var refreshingCount = 0; + + var grid = new Grid (); + var fooViewModel = new FooViewModel (); + var lv = new ListView {BindingContext = fooViewModel, IsGroupingEnabled = true, GroupDisplayBinding = new Binding ("Name"), IsPullToRefreshEnabled = false}; + + var stack = new StackLayout (); + var btn = new Button { Text = string.Format ("IsRefreshing {0}", lv.IsRefreshing) }; + btn.Command = new Command (s => { + lv.IsRefreshing = !lv.IsRefreshing; + btn.Text = string.Format("IsRefreshing {0}",lv.IsRefreshing); + }); + + var btn4 = new Button { Text = "BeginRefresh", Command = new Command (s => { + lv.BeginRefresh(); + btn.Text = string.Format("IsRefreshing {0}",lv.IsRefreshing); + }) }; + var btn1 = new Button { Text = "EndRefresh", Command = new Command (s => { + lv.EndRefresh(); + btn.Text = string.Format("IsRefreshing {0}",lv.IsRefreshing); + }) }; + + var btn2 = new Button { Text = string.Format ("Pull {0}", lv.IsPullToRefreshEnabled) }; + btn2.Command = new Command (s => { + lv.IsPullToRefreshEnabled = !lv.IsPullToRefreshEnabled; + btn2.Text = string.Format("Pull {0}",lv.IsPullToRefreshEnabled); + }); + + var btn3 = new Button { Text = string.Format("CanExecute {0}",fooViewModel.CanExecute) }; + btn3.Command = new Command (s => { + fooViewModel.CanExecute = !fooViewModel.CanExecute; + btn3.Text = string.Format("CanExecute {0}",fooViewModel.CanExecute); + }); + + var lbl = new Label { Text = string.Format ("Refreshing {0}", refreshingCount) }; + lv.Refreshing += (object sender, EventArgs e) => { + refreshingCount++; + lbl.Text = string.Format ("Refreshing {0}", refreshingCount); + }; + + stack.Children.Add (btn); + stack.Children.Add (btn4); + stack.Children.Add (btn1); + stack.Children.Add (btn2); + stack.Children.Add (btn3); + stack.Children.Add (lbl); + lv.Header = new ContentView { HeightRequest = 300, HorizontalOptions = LayoutOptions.FillAndExpand, Content = stack }; + + lv.SetBinding<FooViewModel> (ListView.ItemsSourceProperty, m => m.Things); + lv.SetBinding<FooViewModel> (ListView.RefreshCommandProperty, m => m.RefreshThingsCommand); + grid.Children.Add (lv, 0, 0); + + Content = grid; + } + + public class FooViewModel + { + List<Group<string>> _things; + public List<Group<string>> Things { + get + { + return _things ?? (_things = new List<Group<string>> { + new Group<string>(new []{"A","B","C","D","E","F","G","H","I","J","K"}) {Name = "Letters"}, + new Group<string>(new []{"1","2","3","4","5","6","7","8","9","10"}) {Name = "Numbers"} + }); + } + } + + bool _canExecute; + public bool CanExecute { + get + { + return _canExecute; + } + set { + _canExecute = value; + RefreshThingsCommand.ChangeCanExecute (); + } + } + + Command _refreshThingsCommand; + public Command RefreshThingsCommand { + get {return _refreshThingsCommand ?? (_refreshThingsCommand = new Command (BeginRefreshThings, () => _canExecute ));} + } + + protected void BeginRefreshThings() + { + + } + } + + public class Group<T> : ObservableCollection<T> + { + public Group (IEnumerable<T> seed) : base(seed){} + + public string Name { + get; + set; + } + } + } +} + + diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/ListScrollTo.cs b/Xamarin.Forms.Controls/ControlGalleryPages/ListScrollTo.cs new file mode 100644 index 00000000..9e0d8a67 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/ListScrollTo.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Forms.Controls +{ + public class RandomSizeCell + : TextCell + { + static readonly Random Rand = new Random (42); + + public RandomSizeCell() + { + SetBinding (TextProperty, new Binding (".")); + Height = Rand.Next (25, 60); + } + } + + public class ListScrollTo + : ContentPage + { + readonly List<List<string>> _items = new List<List<string>> (); + bool _animate = true; + readonly ListView _listView; + + public ListScrollTo() + { + Title = "ListView ScrollTo"; + + for (int i = 0; i < 10; i++) { + List<string> subItems = new List<string> (); + for (int x = 0; x < 10; x++) { + subItems.Add (((i * 10) + x + 1).ToString()); + } + + _items.Add (subItems); + } + + _listView = new ListView { + Header = "Fooooo", + Footer = "Baaaaar", + ItemsSource = _items, + IsGroupingEnabled = true, + GroupDisplayBinding = new Binding ("[0]"), + GroupShortNameBinding = new Binding("[0]"), + HasUnevenRows = true, + ItemTemplate = new DataTemplate (typeof(RandomSizeCell)) + }; + + _listView.ScrollTo (_items[2][1], _items[2], ScrollToPosition.Center, true); + + var visible = new Button { Text = "Visible" }; + visible.Clicked += (sender, args) => _listView.ScrollTo (_items[4][4], _items[4], ScrollToPosition.MakeVisible, _animate); + + var start = new Button { Text = "Start" }; + start.Clicked += (sender, args) => _listView.ScrollTo (_items[4][4], _items[4], ScrollToPosition.Start, _animate); + + var center = new Button { Text = "Center"}; + center.Clicked += (sender, args) => _listView.ScrollTo (_items[4][4], _items[4], ScrollToPosition.Center, _animate); + + var end = new Button { Text = "End" }; + end.Clicked += (sender, args) => _listView.ScrollTo (_items[4][4], _items[4], ScrollToPosition.End, _animate); + + var animate = new Button { Text = "Animate" }; + animate.Clicked += (sender, args) => { + _animate = !_animate; + animate.Text = (_animate) ? "Animate" : "No Animate"; + }; + + var buttons = new StackLayout { + Orientation = StackOrientation.Horizontal, + Spacing = 1, + HorizontalOptions = LayoutOptions.Center, + Children = { + visible, + start, + center, + end, + animate + } + }; + + Content = new StackLayout { + Children = { + buttons, + _listView + } + }; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/ListViewSelectionColor.cs b/Xamarin.Forms.Controls/ControlGalleryPages/ListViewSelectionColor.cs new file mode 100644 index 00000000..66a8ad86 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/ListViewSelectionColor.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Forms.Controls +{ + internal sealed class ListViewSelectionColor : ContentPage + { + [Preserve (AllMembers = true)] + internal sealed class GroupHeaderTemplate : ViewCell + { + public GroupHeaderTemplate () + { + var label = new Label { BackgroundColor = Color.Red }; + label.SetBinding (Label.TextProperty, "Key"); + View = label; + } + } + + [Preserve (AllMembers = true)] + internal sealed class GroupItemTemplate : ViewCell + { + public GroupItemTemplate () + { + var label = new Label { BackgroundColor = Color.Green }; + label.SetBinding (Label.TextProperty, "Name"); + View = label; + } + } + + [Preserve (AllMembers = true)] + internal sealed class ItemTemplate : ViewCell + { + public ItemTemplate () + { + var label = new Label { BackgroundColor = Color.Green }; + label.SetBinding (Label.TextProperty, "Name"); + View = label; + } + } + + [Preserve (AllMembers = true)] + internal sealed class Artist + { + public string Name { get; private set; } + + public Artist (string name) + { + Name = name; + } + } + + [Preserve (AllMembers = true)] + internal sealed class Grouping<K, T> : ObservableCollection<T> + { + public K Key { get; private set; } + + public Grouping (K key, IEnumerable<T> values) + { + Key = key; + + foreach (T value in values) { + Items.Add (value); + } + } + } + + Button _swapListButton; + + [Preserve (AllMembers = true)] + public ListViewSelectionColor() + { + Title = "ListView ScrollTo"; + + var itemSource = new [] { + new { Name = "John Hassel" }, + new { Name = "Brian Eno" }, + new { Name = "Rober Fripp" }, + new { Name = "Edgar Froese" } + }; + + var groupedItemSource = new List<Grouping<string, Artist>> { + new Grouping<string, Artist> ("Prog", new List<Artist> { new Artist ("King Crimson"), new Artist ("Yes"), new Artist ("Rush") }), + new Grouping<string, Artist> ("Techno", new List<Artist> { new Artist ("Juan Atkins"), new Artist ("Jeff Mills"), new Artist ("Gerald Donald") } ), + new Grouping<string, Artist> ("Pop", new List<Artist> { new Artist ("Japan"), new Artist ("Roxy Music"), new Artist ("Talking Heads") }), + }; + + var normalList = new ListView { + ItemTemplate = new DataTemplate (typeof (ItemTemplate)), + ItemsSource = itemSource + }; + var groupedList = new ListView { + IsGroupingEnabled = true, + GroupHeaderTemplate = new DataTemplate (typeof (GroupHeaderTemplate)), + ItemTemplate = new DataTemplate (typeof (GroupItemTemplate)), + ItemsSource = groupedItemSource + }; + + var currentList = normalList; + _swapListButton = new Button { + Text = "Swap List Type", + Command = new Command (() => { + if (currentList == normalList) { + SetContent (groupedList); + currentList = groupedList; + } else { + SetContent (normalList); + currentList = normalList; + } + }) + }; + + var clear = new Button { + Text = "Clear", + Command = new Command (() => { + currentList.SelectedItem = null; + }) + }; + + Content = new StackLayout { + Children = { + new StackLayout { + Orientation = StackOrientation.Horizontal, + Children = { + _swapListButton, + clear + } + }, + normalList + } + }; + + } + + void SetContent (ListView list) + { + Content = new StackLayout { + Children = { + _swapListButton, + list + } + }; + } + + + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/NavBarTitleTestPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/NavBarTitleTestPage.cs new file mode 100644 index 00000000..d6031cbe --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/NavBarTitleTestPage.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Forms.Controls +{ + public class NavBarTitleTestPage : ContentPage + { + + public NavBarTitleTestPage () + { + var navTab = new NavigationPage { Title = "Hello 1 nav"}; + navTab.PushAsync (GetPage (navTab)); + + var stackPages = new StackLayout (); + + var btn3 = new Button { + Text = "tab", Command = new Command (async () => { + var tabbed = new TabbedPage { Title = "Main Tab" }; + tabbed.Children.Add (navTab); + tabbed.Children.Add (GetPage (navTab)); + await Navigation.PushModalAsync (tabbed); + }) + }; + + var btn4 = new Button { + Text = "mdp", Command = new Command (async () => { + var newNav = new NavigationPage { Title = "Hello 1 nav", BarBackgroundColor = Color.Pink, BarTextColor = Color.Blue }; + var mdp = new MasterDetailPage (); + await newNav.PushAsync (GetPage (newNav)); + mdp.Master = new ContentPage { + Title = "Master", BackgroundColor = Color.Red, Content = new Button { + Text = "new", Command = new Command (() => { + mdp.Detail = new ContactsPage { Title = "hello 3" }; + mdp.IsPresented = false; + }) + } + }; + mdp.Detail = newNav; + await Navigation.PushModalAsync (mdp); + }) + }; + + var btn5 = new Button { + Text = "nav", Command = new Command (async () => { + var newNav = new NavigationPage { Title = "Hello 1 nav" }; + await newNav.PushAsync (GetPage (newNav)); + await Navigation.PushModalAsync (newNav); + }) + }; + + var btn6 = new Button { + Text = "change nav", Command = new Command (() => { + (Parent as NavigationPage).BarBackgroundColor = Color.Blue; + (Parent as NavigationPage).BarTextColor = Color.Pink; + }) + }; + + stackPages.Children.Add (btn3); + stackPages.Children.Add (btn4); + stackPages.Children.Add (btn5); + stackPages.Children.Add (btn6); + Content = stackPages; + } + + static Page GetPage (NavigationPage navTab) + { + var stack = new StackLayout (); + var newPage = new ContentPage { Title = "Hello 2", Content = stack }; + var btn1 = new Button { Text = "next", Command = new Command (async () => await newPage.Navigation.PushAsync (new ContactsPage { Title = "hello 3" })) }; + var btn2 = new Button { + Text = "change nav", Command = new Command (() => { + navTab.BarBackgroundColor = Color.Blue; + navTab.BarTextColor = Color.Pink; + }) + }; + var btn3 = new Button { + Text = "pop modal", Command = new Command (() => { + newPage.Navigation.PopModalAsync (); + }) + }; + stack.Children.Add (btn1); + stack.Children.Add (btn2); + stack.Children.Add (btn3); + return newPage; + + } + } +} diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/NestedNativeControlGalleryPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/NestedNativeControlGalleryPage.cs new file mode 100644 index 00000000..9f596601 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/NestedNativeControlGalleryPage.cs @@ -0,0 +1,27 @@ +namespace Xamarin.Forms.Controls +{ + public partial class NestedNativeControlGalleryPage : ContentPage + { + public StackLayout Layout { get; set; } + + public bool NativeControlsAdded { get; set; } + + public NestedNativeControlGalleryPage () + { + Layout = new StackLayout { Padding = 20, VerticalOptions = LayoutOptions.FillAndExpand }; + + Content = new ScrollView { Content = Layout }; + + var label = new Label { Text = "There should be some native controls right below this", FontSize = 12 }; + + var testLabel = new Label { Text = "Forms Label", FontSize = 14 }; + var button = new Button { Text = "Resize Forms Label", HeightRequest = 80 }; + double originalSize = testLabel.FontSize; + button.Clicked += (sender, args) => { testLabel.FontSize = testLabel.FontSize == originalSize ? 24 : 14; }; + + Layout.Children.Add(testLabel); + Layout.Children.Add(button); + Layout.Children.Add(label); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/PanGestureGalleryPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/PanGestureGalleryPage.cs new file mode 100644 index 00000000..b37e8e48 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/PanGestureGalleryPage.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Forms.Controls +{ + public class PanGestureGalleryPage : ContentPage + { + public class PanContainer : ContentView + { + public PanContainer () + { + var pan = new PanGestureRecognizer + { + TouchPoints = 1 + }; + + pan.PanUpdated += (object s, PanUpdatedEventArgs e) => + { + switch (e.StatusType) { + + case GestureStatus.Started: break; + + case GestureStatus.Running: + Content.TranslationX = e.TotalX; + Content.TranslationY = e.TotalY; + break; + + default: + Content.TranslationX = Content.TranslationY = 0; + break; + } + }; + + var pinch = new PinchGestureRecognizer (); + + double xOffset = 0; + double yOffset = 0; + double startScale = 1; + + pinch.PinchUpdated += (sender, e) => + { + + if (e.Status == GestureStatus.Started) { + startScale = Content.Scale; + Content.AnchorX = Content.AnchorY = 0; + } + if (e.Status == GestureStatus.Running) { + + _currentScale += (e.Scale - 1) * startScale; + _currentScale = Math.Max (1, _currentScale); + + var renderedX = Content.X + xOffset; + var deltaX = renderedX / Width; + var deltaWidth = Width / (Content.Width * startScale); + var originX = (e.ScaleOrigin.X - deltaX) * deltaWidth; + + var renderedY = Content.Y + yOffset; + var deltaY = renderedY / Height; + var deltaHeight = Height / (Content.Height * startScale); + var originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight; + + double targetX = xOffset - (originX * Content.Width) * (_currentScale - startScale); + double targetY = yOffset - (originY * Content.Height) * (_currentScale - startScale); + + Content.TranslationX = targetX.Clamp (-Content.Width * (_currentScale - 1), 0); + Content.TranslationY = targetY.Clamp (-Content.Height * (_currentScale - 1), 0); + + Content.Scale = _currentScale; + } + if (e.Status == GestureStatus.Completed) { + xOffset = Content.TranslationX; + yOffset = Content.TranslationY; + } + }; + + GestureRecognizers.Add (pinch); + + GestureRecognizers.Add (pan); + } + + double _currentScale = 1; + } + + public PanGestureGalleryPage () + { + var image = new Image { Source = "http://placehold.it/2000x2000", BackgroundColor = Color.Gray, WidthRequest = 2000, HeightRequest = 2000, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }; + + var panme = new PanContainer { Content = image }; + + Content = new StackLayout { Children = { new Label { Text = "Use two fingers to pinch. Use one finger to pan." }, panme }, Padding = new Thickness (20) }; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/PinchGestureTestPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/PinchGestureTestPage.cs new file mode 100644 index 00000000..44dd6ae8 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/PinchGestureTestPage.cs @@ -0,0 +1,91 @@ +using System; +using System.Diagnostics; + +namespace Xamarin.Forms.Controls +{ + public class PinchToZoomContainer : ContentView + { + public PinchToZoomContainer () + { + + } + + public void AddPinch () + { + + var pinch = new PinchGestureRecognizer (); + + double xOffset = 0; + double yOffset = 0; + double startScale = 1; + + pinch.PinchUpdated += (sender, e) => { + + if (e.Status == GestureStatus.Started) { + startScale = Content.Scale; + Content.AnchorX = Content.AnchorY = 0; + } + if (e.Status == GestureStatus.Running) { + + _currentScale += (e.Scale - 1) * startScale; + _currentScale = Math.Max (1, _currentScale); + + var renderedX = Content.X + xOffset; + var deltaX = renderedX / Width; + var deltaWidth = Width / (Content.Width * startScale); + var originX = (e.ScaleOrigin.X - deltaX) * deltaWidth; + + var renderedY = Content.Y + yOffset; + var deltaY = renderedY / Height; + var deltaHeight = Height / (Content.Height * startScale); + var originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight; + + double targetX = xOffset - (originX * Content.Width) * (_currentScale - startScale); + double targetY = yOffset - (originY * Content.Height) * (_currentScale - startScale); + + Content.TranslationX = targetX.Clamp (-Content.Width * (_currentScale - 1), 0); + Content.TranslationY = targetY.Clamp (-Content.Height * (_currentScale - 1), 0); + + Content.Scale = _currentScale; + } + if (e.Status == GestureStatus.Completed) { + xOffset = Content.TranslationX; + yOffset = Content.TranslationY; + } + }; + + GestureRecognizers.Add (pinch); + } + + public bool AlwaysZoomCenter { get; set; } + + double _currentScale = 1; + } + + public class PinchGestureTestPage : ContentPage + { + public PinchGestureTestPage () + { + var stack = new StackLayout { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center }; + var textBoxScale = new Label { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center }; + var textBox = new Label { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center }; + var textBoxPoint = new Label { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center }; + stack.Children.Add (textBox); + stack.Children.Add (textBoxScale); + stack.Children.Add (textBoxPoint); + + var box = new Image { Source = "crimson.jpg", BackgroundColor = Color.Red, WidthRequest = 200, HeightRequest = 200, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }; + + var zoomContainer = new PinchToZoomContainer (); + zoomContainer.Content = box; + + var btn = new Button { Text = "add pinch gesture", Command = new Command (() => zoomContainer.AddPinch ()) }; + var btnRemove = new Button { Text = "remove pinch gesture", Command = new Command (() => zoomContainer.GestureRecognizers.Clear ()) }; + + Content = new StackLayout { Children = { btn, btnRemove, new Grid { Children = { zoomContainer }, Padding = new Thickness (20) } } }; + } + + double _currentScale = 1; + } +} + diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/ToolbarItems.cs b/Xamarin.Forms.Controls/ControlGalleryPages/ToolbarItems.cs new file mode 100644 index 00000000..3e98fc88 --- /dev/null +++ b/Xamarin.Forms.Controls/ControlGalleryPages/ToolbarItems.cs @@ -0,0 +1,55 @@ +using System; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Controls +{ + public class ToolbarItems : ContentPage + { + bool _isEnable = false; + public ToolbarItems () + { + var label = new Label { Text = "Hello ContentPage", AutomationId ="label_id" }; + + var tb1 = new ToolbarItem ("tb1", "menuIcon.png", () => { + label.Text = "tb1"; + }, ToolbarItemOrder.Primary); + tb1.IsEnabled = _isEnable; + tb1.AutomationId = "toolbaritem_primary"; + tb1.IsEnabled = _isEnable; + + var tb2 = new ToolbarItem ("tb2", null, () => { + label.Text = "tb2"; + }, ToolbarItemOrder.Primary); + tb2.AutomationId = "toolbaritem_primary2"; + + var tb3 = new ToolbarItem ("tb3", "bank.png", () => { + label.Text = "tb3"; + }, ToolbarItemOrder.Secondary); + tb3.AutomationId = "toolbaritem_secondary"; + + var tb4 = new ToolbarItem (); + tb4.Text = "tb4"; + tb4.Order = ToolbarItemOrder.Secondary; + tb4.Command = new Command( (obj)=> { + _isEnable = true; + label.Text = "tb4"; + (tb4.Command as Command).ChangeCanExecute(); + },(obj) => _isEnable); + tb4.AutomationId = "toolbaritem_secondary2"; + + ToolbarItems.Add(tb1); + ToolbarItems.Add(tb2); + ToolbarItems.Add(tb3); + ToolbarItems.Add(tb4); + + Content = new StackLayout { + Children = { + label + } + }; + } + } +} + + |