From 8e770dec034578e5055c5c1c2ecea65de86c869c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Wed, 13 Oct 2021 13:47:50 +0200 Subject: [PATCH 1/2] Added XAML samples --- .../GraphicsControls.Sample/App.xaml.cs | 2 +- .../CustomControlsPage.cs | 38 +- .../CustomNavigationPage.cs | 14 + .../GalleryPageCSharp.cs | 265 ++++++++++++ .../GalleryPageXAML.xaml | 257 ++++++++++++ .../GalleryPageXAML.xaml.cs | 12 + .../GraphicsControls.Sample/MainPage.cs | 378 +++++++----------- .../GraphicsControls.Sample/SampleColors.cs | 12 + src/GraphicsControls/GraphicsControls.csproj | 4 +- 9 files changed, 717 insertions(+), 265 deletions(-) create mode 100644 src/GraphicsControls.Sample/GraphicsControls.Sample/CustomNavigationPage.cs create mode 100644 src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageCSharp.cs create mode 100644 src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageXAML.xaml create mode 100644 src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageXAML.xaml.cs create mode 100644 src/GraphicsControls.Sample/GraphicsControls.Sample/SampleColors.cs diff --git a/src/GraphicsControls.Sample/GraphicsControls.Sample/App.xaml.cs b/src/GraphicsControls.Sample/GraphicsControls.Sample/App.xaml.cs index 3627be0..4de8263 100644 --- a/src/GraphicsControls.Sample/GraphicsControls.Sample/App.xaml.cs +++ b/src/GraphicsControls.Sample/GraphicsControls.Sample/App.xaml.cs @@ -9,7 +9,7 @@ namespace GraphicsControls.Sample InitializeComponent(); //MainPage = new CustomControlsPage(); - MainPage = new MainPage(); + MainPage = new CustomNavigationPage(new MainPage()); } } } diff --git a/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomControlsPage.cs b/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomControlsPage.cs index 2083374..8a94202 100644 --- a/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomControlsPage.cs +++ b/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomControlsPage.cs @@ -7,20 +7,16 @@ namespace GraphicsControls.Sample { public class CustomControlsPage : ContentPage { - readonly Color PageBackgroundColor = Color.FromArgb("#FFFFFF"); - readonly Color SectionHeaderBackgroundColor = Color.FromArgb("#E9E9E9"); - readonly Color SectionBackgroundColor = Color.FromArgb("#FAFAFA"); - public CustomControlsPage() { - BackgroundColor = PageBackgroundColor; + Title = "Customize using Microsoft.Maui.Graphics.Controls"; + + BackgroundColor = SampleColors.PageBackgroundColor; var scrollView = new ScrollView(); var verticalStack = new StackLayout() { Margin = 12 }; - verticalStack.Add(CreateHeader()); - verticalStack.Add(CreateDrawCustomSlider()); //verticalStack.Add(CreateCustomSliderMapper()); verticalStack.Add(CreateCustomSliderDrawable()); @@ -31,38 +27,16 @@ namespace GraphicsControls.Sample Content = scrollView; } - IView CreateHeader() - { - var container = new StackLayout(); - - container.Add(new Label - { - FontSize = 18, - FontAttributes = FontAttributes.Bold, - Text = "Customize using Microsoft.Maui.Graphics.Controls", - TextColor = Colors.Black, - Margin = new Thickness(0, 24, 0, 0) - }); - - container.Add(new Label - { - Text = "An example where learn how to customize existing controls as well as create new drawn controls.", - TextColor = Colors.Black - }); - - return container; - } - IView CreateContainer(string title, View content) { var contentContainer = new StackLayout { - BackgroundColor = SectionBackgroundColor + BackgroundColor = SampleColors.SectionBackgroundColor }; var header = new Label { - BackgroundColor = SectionHeaderBackgroundColor, + BackgroundColor = SampleColors.SectionHeaderBackgroundColor, Padding = 12, Text = title, TextColor = Colors.Black @@ -73,7 +47,7 @@ namespace GraphicsControls.Sample var container = new Grid { - BackgroundColor = SectionBackgroundColor, + BackgroundColor = SampleColors.SectionBackgroundColor, Padding = 0, Margin = new Thickness(0, 6) }; diff --git a/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomNavigationPage.cs b/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomNavigationPage.cs new file mode 100644 index 0000000..463f6c4 --- /dev/null +++ b/src/GraphicsControls.Sample/GraphicsControls.Sample/CustomNavigationPage.cs @@ -0,0 +1,14 @@ +using Microsoft.Maui.Controls; +using Microsoft.Maui.Graphics; + +namespace GraphicsControls.Sample +{ + public class CustomNavigationPage : NavigationPage + { + public CustomNavigationPage(Page page) : base(page) + { + BarBackgroundColor = SampleColors.AccentColor; + BarTextColor = Colors.White; + } + } +} \ No newline at end of file diff --git a/src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageCSharp.cs b/src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageCSharp.cs new file mode 100644 index 0000000..caaf43c --- /dev/null +++ b/src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageCSharp.cs @@ -0,0 +1,265 @@ +using Microsoft.Maui; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Graphics; +using System.Diagnostics; +using Switch = Microsoft.Maui.Controls.Switch; + +namespace GraphicsControls.Sample +{ + public class GalleryPageCSharp : ContentPage + { + public GalleryPageCSharp() + { + Title = "C# Gallery"; + + BackgroundColor = SampleColors.PageBackgroundColor; + + var scrollView = new ScrollView(); + + var verticalStack = new StackLayout() { Margin = 12 }; + + verticalStack.Add(CreateButton()); + verticalStack.Add(CreateCheckBox()); + verticalStack.Add(CreateDatePicker()); + verticalStack.Add(CreateEditor()); + verticalStack.Add(CreateEntry()); + verticalStack.Add(CreateProgressBar()); + verticalStack.Add(CreateSlider()); + verticalStack.Add(CreateStepper()); + verticalStack.Add(CreateSwitch()); + verticalStack.Add(CreateTimePicker()); + + scrollView.Content = verticalStack; + + Content = scrollView; + } + + IView CreateContainer(string title, View content) + { + var contentContainer = new StackLayout + { + BackgroundColor = SampleColors.SectionBackgroundColor + }; + + var header = new Label + { + BackgroundColor = SampleColors.SectionHeaderBackgroundColor, + Padding = 12, + Text = title, + TextColor = Colors.Black + }; + + contentContainer.Children.Add(header); + contentContainer.Children.Add(content); + + var container = new Grid + { + BackgroundColor = SampleColors.SectionBackgroundColor, + Padding = 0, + Margin = new Thickness(0, 6) + }; + + container.Children.Add(contentContainer); + + return container; + } + + IView CreateButton() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Button" }); + + var defaultButton = new Button { Text = "Button" }; + + defaultButton.Clicked += (sender, args) => + { + Debug.WriteLine("Button Clicked"); + }; + + layout.Children.Add(defaultButton); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled Button" }); + layout.Children.Add(new Button { IsEnabled = false, Text = "Disabled Button" }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom Button" }); + layout.Children.Add(new Button { BackgroundColor = Colors.Red, TextColor = Colors.Yellow, Text = "Custom Button" }); + + return CreateContainer("Button", layout); + } + + IView CreateCheckBox() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new CheckBox { IsChecked = true }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new CheckBox { IsEnabled = false, IsChecked = true }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new CheckBox { BackgroundColor = Colors.Purple, IsChecked = true }); + + return CreateContainer("CheckBox", layout); + } + + IView CreateDatePicker() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new DatePicker()); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new DatePicker { IsEnabled = false }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new DatePicker { BackgroundColor = Colors.LightGreen, TextColor = Colors.White }); + + return CreateContainer("DatePicker", layout); + } + + IView CreateEditor() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new Editor { Placeholder = "Placeholder" }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new Editor { IsEnabled = false, Placeholder = "Placeholder" }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new Editor { BackgroundColor = Colors.LightPink, TextColor = Colors.DeepPink, Placeholder = "Placeholder", PlaceholderColor = Colors.HotPink }); + + return CreateContainer("Editor", layout); + } + + IView CreateEntry() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new Entry { Placeholder = "Placeholder" }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new Entry { IsEnabled = false, Placeholder = "Placeholder" }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new Entry { BackgroundColor = Colors.LightBlue, TextColor = Colors.Blue, Placeholder = "Placeholder", PlaceholderColor = Colors.DarkBlue }); + + return CreateContainer("Entry", layout); + } + + IView CreateProgressBar() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new ProgressBar { Progress = 0.5d }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "ProgressBar" }); + layout.Children.Add(new ProgressBar { IsEnabled = false, Progress = 0.5d }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "ProgressBar" }); + layout.Children.Add(new ProgressBar { ProgressColor = Colors.Orange, Progress = 0.5d }); + + return CreateContainer("ProgressBar", layout); + } + + IView CreateSlider() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new Slider { Minimum = 0, Maximum = 10, Value = 5 }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new Slider { IsEnabled = false, Minimum = 0, Maximum = 10, Value = 5 }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new Slider { Minimum = 0, MinimumTrackColor = Colors.Orange, Maximum = 10, MaximumTrackColor = Colors.YellowGreen, Value = 5, ThumbColor = Colors.BlueViolet }); + + return CreateContainer("Slider", layout); + } + + IView CreateStepper() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new Stepper { Minimum = 0, Maximum = 10, Value = 5, Increment = 1 }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new Stepper { IsEnabled = false, Minimum = 0, Maximum = 10, Value = 5, Increment = 1 }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new Stepper { BackgroundColor = Colors.CadetBlue, Minimum = 0, Maximum = 10, Value = 5, Increment = 1 }); + + return CreateContainer("Stepper", layout); + } + + IView CreateSwitch() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new Switch { IsToggled = true }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new Switch { IsEnabled = false, IsToggled = true }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new Switch { OnColor = Colors.YellowGreen, ThumbColor = Colors.Green, IsToggled = true }); + + return CreateContainer("Switch", layout); + } + + IView CreateTimePicker() + { + var layout = new StackLayout + { + Margin = new Thickness(12, 6, 12, 24) + }; + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Default" }); + layout.Children.Add(new TimePicker()); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Disabled" }); + layout.Children.Add(new TimePicker { IsEnabled = false }); + + layout.Children.Add(new Label { FontSize = 9, TextColor = Colors.Gray, Text = "Custom" }); + layout.Children.Add(new TimePicker { BackgroundColor = Colors.LightSkyBlue, TextColor = Colors.White }); + + return CreateContainer("TimePicker", layout); + } + } +} \ No newline at end of file diff --git a/src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageXAML.xaml b/src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageXAML.xaml new file mode 100644 index 0000000..49d68a1 --- /dev/null +++ b/src/GraphicsControls.Sample/GraphicsControls.Sample/GalleryPageXAML.xaml @@ -0,0 +1,257 @@ + + + + + + #FAFAFA + #E9E9E9 + + + + + + + + + + +