Skip to content

Commit

Permalink
feat: add lightweight extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Antoine-Soucy committed Jul 31, 2023
1 parent deb6534 commit a6d6000
Show file tree
Hide file tree
Showing 15 changed files with 942 additions and 4 deletions.
56 changes: 56 additions & 0 deletions Uno.Gallery/Uno.Gallery.Shared/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using Windows.UI.Xaml;

namespace Uno.Gallery
{
/// <summary>
/// Helper class for Controls Extensions.
/// </summary>
public static class ControlExtensions
{
public static readonly DependencyProperty ResourcePathProperty =
DependencyProperty.RegisterAttached(
"ResourcePath",
typeof(string),
typeof(ControlExtensions),
new PropertyMetadata(null, OnResourcePathChanged));

public static void SetResourcePath(FrameworkElement element, string value)
{
element.SetValue(ResourcePathProperty, value);
}

public static string GetResourcePath(FrameworkElement element)
{
return (string)element.GetValue(ResourcePathProperty);
}

private static void OnResourcePathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as FrameworkElement;
if (control != null)
{
var resourcePath = (string)e.NewValue;
AddResourcesFromPath(control, resourcePath);
}
}

private static void AddResourcesFromPath(FrameworkElement control, string resourcePath)
{
// Load the resource dictionary
var resources = new ResourceDictionary()
{
Source = new Uri(resourcePath, UriKind.RelativeOrAbsolute)
};

// Add or replace the resources in this control's resource dictionary
foreach (var key in resources.Keys)
{
if (control.Resources.ContainsKey(key))
control.Resources[key] = resources[key];
else
control.Resources.Add(key, resources[key]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Entities\Design.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Entities\SourceSdk.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ClipboardExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ControlExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\XamlDisplayExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\Disposable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\EnumHelper.cs" />
Expand Down
46 changes: 43 additions & 3 deletions Uno.Gallery/Uno.Gallery.UWP/Uno.Gallery.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Uno.Toolkit.UI.Cupertino">
<Version>3.1.0-dev.24</Version>
<Version>4.0.0-dev.55</Version>
</PackageReference>
<PackageReference Include="Uno.Toolkit.UI.Material">
<Version>3.1.0-dev.24</Version>
<Version>4.0.0-dev.55</Version>
</PackageReference>
<PackageReference Include="Uno.UI">
<Version>5.0.0-dev.1728</Version>
Expand Down Expand Up @@ -213,6 +213,9 @@
<Compile Include="Views\NestedPages\NavigationBarSample_NestedPage2.xaml.cs">
<DependentUpon>NavigationBarSample_NestedPage2.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SamplePages\LightWeightExtensionSameplePage.xaml.cs">
<DependentUpon>LightWeightExtensionSameplePage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SamplePages\TreeViewSamplePage.xaml.cs">
<DependentUpon>TreeViewSamplePage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -540,6 +543,34 @@
<Content Include="Properties\Default.rd.xml" />
</ItemGroup>
<ItemGroup>
<Page Include="Views\ControlResourcesOverride\Fluent\Button.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Material\Button.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Fluent\CheckBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Fluent\RadioButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Material\RadioButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Fluent\TextBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Material\TextBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\CupertinoFontsOverride.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -604,6 +635,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SamplePages\LightWeightExtensionSameplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SamplePages\TreeViewSamplePage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -968,6 +1003,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlResourcesOverride\Material\CheckBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Styles\FontIcons.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -1048,6 +1087,7 @@
<ItemGroup>
<Content Include="Assets\Fonts\Cupertino\SF-Pro-Text-Regular.otf" />
</ItemGroup>
<ItemGroup />
<Import Project="..\Uno.Gallery.Shared\Uno.Gallery.Shared.projitems" Label="Shared" Condition="Exists('..\Uno.Gallery.Shared\Uno.Gallery.Shared.projitems')" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
Expand All @@ -1060,4 +1100,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<SolidColorBrush x:Key="ButtonForeground"
Color="DarkGreen" />
<SolidColorBrush x:Key="ButtonBackground"
Color="LightGreen" />
<SolidColorBrush x:Key="ButtonBorderBrush"
Color="DarkGreen" />

<SolidColorBrush x:Key="ButtonForegroundPointerOver"
Color="DarkRed" />
<SolidColorBrush x:Key="ButtonBackgroundPointerOver"
Color="LightPink" />
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver"
Color="DarkRed" />

<SolidColorBrush x:Key="ButtonForegroundPressed"
Color="DarkBlue" />
<SolidColorBrush x:Key="ButtonBackgroundPressed"
Color="LightSteelBlue" />
<SolidColorBrush x:Key="ButtonBorderBrushPressed"
Color="DarkBlue" />

<SolidColorBrush x:Key="ButtonForegroundDisabled"
Color="LightSlateGray" />
<SolidColorBrush x:Key="ButtonBackgroundDisabled"
Color="DarkGray" />
<SolidColorBrush x:Key="ButtonBorderBrushDisabled"
Color="LightSlateGray" />

</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<!-- Checked state -->
<SolidColorBrush x:Key="CheckBoxCheckGlyphForegroundChecked"
Color="Teal" />
<SolidColorBrush x:Key="CheckBoxBorderBrushChecked"
Color="Navy" />
<SolidColorBrush x:Key="CheckBoxBackgroundChecked"
Color="Maroon" />

<!-- Checked and pointer over state -->
<SolidColorBrush x:Key="CheckBoxCheckGlyphForegroundCheckedPointerOver"
Color="Lime" />
<SolidColorBrush x:Key="CheckBoxBorderBrushCheckedPointerOver"
Color="Olive" />
<SolidColorBrush x:Key="CheckBoxBackgroundCheckedPointerOver"
Color="Silver" />

<!-- Checked and pressed state -->
<SolidColorBrush x:Key="CheckBoxCheckGlyphForegroundCheckedPressed"
Color="Purple" />
<SolidColorBrush x:Key="CheckBoxBorderBrushCheckedPressed"
Color="Aqua" />
<SolidColorBrush x:Key="CheckBoxBackgroundCheckedPressed"
Color="Yellow" />

<!-- Unchecked state -->
<SolidColorBrush x:Key="CheckBoxCheckGlyphForegroundUnchecked"
Color="Black" />
<SolidColorBrush x:Key="CheckBoxBorderBrushUnchecked"
Color="White" />
<SolidColorBrush x:Key="CheckBoxBackgroundUnchecked"
Color="Gray" />

<!-- Unchecked and pointer over state -->
<SolidColorBrush x:Key="CheckBoxCheckGlyphForegroundUncheckedPointerOver"
Color="Blue" />
<SolidColorBrush x:Key="CheckBoxBorderBrushUncheckedPointerOver"
Color="Orange" />
<SolidColorBrush x:Key="CheckBoxBackgroundUncheckedPointerOver"
Color="Green" />

<!-- Unchecked and pressed state -->
<SolidColorBrush x:Key="CheckBoxCheckGlyphForegroundUncheckedPressed"
Color="Red" />
<SolidColorBrush x:Key="CheckBoxBorderBrushUncheckedPressed"
Color="Cyan" />
<SolidColorBrush x:Key="CheckBoxBackgroundUncheckedPressed"
Color="Pink" />

</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<SolidColorBrush x:Key="RadioButtonForeground"
Color="DarkGreen" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseStroke"
Color="LightGreen" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedStroke"
Color="DarkGreen" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseFill"
Color="LightGreen" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedFill"
Color="DarkGreen" />

<SolidColorBrush x:Key="RadioButtonForegroundPointerOver"
Color="DarkRed" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseStrokePointerOver"
Color="LightPink" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedStrokePointerOver"
Color="DarkRed" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseFillPointerOver"
Color="LightPink" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedFillPointerOver"
Color="DarkRed" />

<SolidColorBrush x:Key="RadioButtonForegroundPressed"
Color="DarkBlue" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseStrokePressed"
Color="LightSteelBlue" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedStrokePressed"
Color="DarkBlue" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseFillPressed"
Color="LightSteelBlue" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedFillPressed"
Color="DarkBlue" />

<SolidColorBrush x:Key="RadioButtonForegroundDisabled"
Color="LightSlateGray" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseStrokeDisabled"
Color="DarkGray" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedStrokeDisabled"
Color="LightSlateGray" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseFillDisabled"
Color="DarkGray" />
<SolidColorBrush x:Key="RadioButtonOuterEllipseCheckedFillDisabled"
Color="LightSlateGray" />

</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<!-- Default State -->
<SolidColorBrush x:Key="TextControlForeground"
Color="Red" />
<SolidColorBrush x:Key="TextControlBackground"
Color="Cyan" />

<!-- Pointer Over State -->
<SolidColorBrush x:Key="TextControlButtonBackgroundPointerOver"
Color="Orange" />
<SolidColorBrush x:Key="TextControlBackgroundPointerOver"
Color="Navy" />
<SolidColorBrush x:Key="TextControlForegroundPointerOver"
Color="Gray" />

<!-- Focused State -->
<SolidColorBrush x:Key="TextControlForegroundFocused"
Color="Yellow" />
<SolidColorBrush x:Key="TextControlBackgroundFocused"
Color="RosyBrown" />

</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<SolidColorBrush x:Key="FilledButtonForeground"
Color="DarkGreen" />
<SolidColorBrush x:Key="FilledButtonBackground"
Color="LightGreen" />
<SolidColorBrush x:Key="FilledButtonBorderBrush"
Color="DarkGreen" />

<SolidColorBrush x:Key="FilledButtonForegroundPointerOver"
Color="DarkRed" />
<SolidColorBrush x:Key="FilledButtonBackgroundPointerOver"
Color="LightPink" />
<SolidColorBrush x:Key="FilledButtonBorderBrushPointerOver"
Color="DarkRed" />

<SolidColorBrush x:Key="FilledButtonForegroundPressed"
Color="DarkBlue" />
<SolidColorBrush x:Key="FilledButtonBackgroundPressed"
Color="LightSteelBlue" />
<SolidColorBrush x:Key="FilledButtonBorderBrushPressed"
Color="DarkBlue" />

<SolidColorBrush x:Key="FilledButtonForegroundFocused"
Color="AntiqueWhite" />
<SolidColorBrush x:Key="FilledButtonBackgroundFocused"
Color="DarkMagenta" />
<SolidColorBrush x:Key="FilledButtonBorderBrushFocused"
Color="AntiqueWhite" />

<SolidColorBrush x:Key="FilledButtonForegroundDisabled"
Color="LightSlateGray" />
<SolidColorBrush x:Key="FilledButtonBackgroundDisabled"
Color="DarkGray" />
<SolidColorBrush x:Key="FilledButtonBorderBrushDisabled"
Color="LightSlateGray" />

</ResourceDictionary>
Loading

0 comments on commit a6d6000

Please sign in to comment.