From b81b7363cd3fa8aa2764f339cd967bd884aadfe9 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Soucy Date: Thu, 10 Aug 2023 11:11:00 -0400 Subject: [PATCH] feat: add lightweight extension --- Settings.XamlStyler | 2 +- .../Extensions/ResourceExtensions.cs | 38 ++ .../Uno.Gallery.Shared.projitems | 38 ++ .../Uno.Gallery.Shared.shproj | 6 + .../Fluent/Button.xaml | 19 + .../Fluent/CheckBox.xaml | 33 ++ .../Fluent/RadioButton.xaml | 27 ++ .../Fluent/TextBox.xaml | 16 + .../Material/Button.xaml | 23 + .../Material/CheckBox.xaml | 30 ++ .../Material/RadioButton.xaml | 27 ++ .../Material/TextBox.xaml | 18 + .../LightWeightExtensionSameplePage.xaml | 400 ++++++++++++++++++ .../LightWeightExtensionSameplePage.xaml.cs | 13 + .../Views/Styles/Button.xaml | 8 + 15 files changed, 697 insertions(+), 1 deletion(-) create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Extensions/ResourceExtensions.cs create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/Button.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/CheckBox.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/RadioButton.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/TextBox.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/Button.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/CheckBox.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/RadioButton.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/TextBox.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/SamplePages/LightWeightExtensionSameplePage.xaml create mode 100644 Uno.Gallery/Uno.Gallery.Shared/Views/SamplePages/LightWeightExtensionSameplePage.xaml.cs diff --git a/Settings.XamlStyler b/Settings.XamlStyler index 3d76cddc6..059bef472 100644 --- a/Settings.XamlStyler +++ b/Settings.XamlStyler @@ -3,7 +3,7 @@ "KeepFirstAttributeOnSameLine": true, "MaxAttributeCharactersPerLine": 0, "MaxAttributesPerLine": 1, - "NewlineExemptionElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransform, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter, StaticResource", + "NewlineExemptionElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransform, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter, StaticResource, SolidColorBrush", "SeparateByGroups": false, "AttributeIndentation": 0, "AttributeIndentationStyle": 0, diff --git a/Uno.Gallery/Uno.Gallery.Shared/Extensions/ResourceExtensions.cs b/Uno.Gallery/Uno.Gallery.Shared/Extensions/ResourceExtensions.cs new file mode 100644 index 000000000..3382307d6 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Extensions/ResourceExtensions.cs @@ -0,0 +1,38 @@ +using Microsoft.UI.Xaml; +using System; + +namespace Uno.Gallery +{ + /// + /// Helper class for Resources Extensions. + /// + public static class ResourceExtensions + { + public static readonly DependencyProperty OverridePathProperty = + DependencyProperty.RegisterAttached( + "OverridePath", + typeof(string), + typeof(ResourceExtensions), + new PropertyMetadata(null, OnOverridePathChanged)); + + public static void SetOverridePath(FrameworkElement element, string value) + { + element.SetValue(OverridePathProperty, value); + } + + public static string GetOverridePath(FrameworkElement element) + { + return (string)element.GetValue(OverridePathProperty); + } + + private static void OnOverridePathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is FrameworkElement fe) + { + fe.Resources = e.NewValue is string path + ? new ResourceDictionary() { Source = new Uri(path, UriKind.RelativeOrAbsolute) } + : default; + } + } + } +} diff --git a/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.projitems b/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.projitems index 71a767a8a..13398256e 100644 --- a/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.projitems +++ b/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.projitems @@ -173,6 +173,7 @@ + @@ -180,12 +181,49 @@ + Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + <_Globbled_Page Include="$(MSBuildThisFileDirectory)**/*.xaml" Exclude="@(Page);@(ApplicationDefinition)"> Designer MSBuild:Compile diff --git a/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.shproj b/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.shproj index 451a2c1af..395bb7445 100644 --- a/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.shproj +++ b/Uno.Gallery/Uno.Gallery.Shared/Uno.Gallery.Shared.shproj @@ -10,4 +10,10 @@ + + <_Globbed_Compile Remove="Views\SamplePages\LightWeightExtensionSameplePage.xaml.cs" /> + + + <_Globbled_Page Remove="Views\SamplePages\LightWeightExtensionSameplePage.xaml" /> + \ No newline at end of file diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/Button.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/Button.xaml new file mode 100644 index 000000000..f897eaba6 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/Button.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/CheckBox.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/CheckBox.xaml new file mode 100644 index 000000000..999548ea5 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/CheckBox.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/RadioButton.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/RadioButton.xaml new file mode 100644 index 000000000..db7f43f0d --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/RadioButton.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/TextBox.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/TextBox.xaml new file mode 100644 index 000000000..f68d33743 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Fluent/TextBox.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/Button.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/Button.xaml new file mode 100644 index 000000000..71a8b0441 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/Button.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/CheckBox.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/CheckBox.xaml new file mode 100644 index 000000000..bfe92fa25 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/CheckBox.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/RadioButton.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/RadioButton.xaml new file mode 100644 index 000000000..db7f43f0d --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/RadioButton.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/TextBox.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/TextBox.xaml new file mode 100644 index 000000000..17d7e257d --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/ControlResourcesOverride/Material/TextBox.xaml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + diff --git a/Uno.Gallery/Uno.Gallery.Shared/Views/SamplePages/LightWeightExtensionSameplePage.xaml b/Uno.Gallery/Uno.Gallery.Shared/Views/SamplePages/LightWeightExtensionSameplePage.xaml new file mode 100644 index 000000000..1a5da9a19 --- /dev/null +++ b/Uno.Gallery/Uno.Gallery.Shared/Views/SamplePages/LightWeightExtensionSameplePage.xaml @@ -0,0 +1,400 @@ + + + + + + + + + + + +