Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Propagating StyleClass on ShellElements to Flyout templates #9886

Merged
merged 8 commits into from Apr 3, 2020

Conversation

PureWeen
Copy link
Contributor

@PureWeen PureWeen commented Mar 8, 2020

Description of Change

Added default style Classes. If users set any of these it will automatically just apply those styles to all of the items

		const string DefaultFlyoutItemLabelStyle = "FlyoutItemLabelStyle";
		const string DefaultFlyoutItemImageStyle = "FlyoutItemImageStyle";
		const string DefaultFlyoutItemStyle = "FlyoutItemLayoutStyle";

Fix UWP to use flyout/menu item templates

When a user sets the StyleClass on a BaseShellElement, propagate that StyleClass to the default template for the flyout items

All style classes are added to the Grid/Label/Image that make up the template so you can style anything

As customization grows (tabs, etc..) these styles can get applied to those as well. At which point we will most likely expand this to attached properties so you can specify Tab.StyleClass and FlyoutItem.StyleClass to articulate the style class for different contexts

 <Shell.Resources>
<!-- Create a style for the Label that's part of the flyout template-->
        <Style TargetType="Label"
               Class="FlyoutLabelClass">
            <Setter Property="TextColor"
                    Value="#000000" />
            <Setter Property="HeightRequest"
                    Value="100" />
        </Style>
<!-- Set the height of the flyout container -->
        <Style TargetType="Layout" ApplyToDerivedTypes="True"
               Class="FlyoutGridClass">
            <Setter Property="HeightRequest"
                    Value="120" />
        </Style>
<!-- Set the height of a different flyout container -->
        <Style TargetType="Layout" ApplyToDerivedTypes="True"
               Class="FlyoutGridClass2">
            <Setter Property="HeightRequest"
                    Value="50" />
            <Setter Property="BackgroundColor"
                    Value="Blue" />
        </Style>
    </Shell.Resources>
    <FlyoutItem Title="Sandbox" StyleClass="FlyoutLabelClass, FlyoutGridClass">
        <Tab>
            <ShellContent ContentTemplate="{DataTemplate local:MainPage}">
            </ShellContent>
        </Tab>
    </FlyoutItem>
    <FlyoutItem Title="Sandbox2" StyleClass="FlyoutLabelClass, FlyoutGridClass2">
        <Tab>
            <ShellContent ContentTemplate="{DataTemplate local:MainPage}">
            </ShellContent>
        </Tab>
    </FlyoutItem>

Issues Resolved

Platforms Affected

  • Core/XAML (all platforms)

Behavioral/Visual Changes

90F4DF70-6165-422E-95F1-B505DAA81F56

Testing Procedure

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@PureWeen PureWeen added the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Mar 8, 2020
@samhouts samhouts added this to In Progress in vCurrent (4.8.0) Mar 9, 2020
@PureWeen PureWeen force-pushed the shell_flyout_styling branch 2 times, most recently from 5cde4d5 to 7b081c8 Compare March 9, 2020 21:16
@PureWeen PureWeen changed the base branch from master to 4.6.0 March 9, 2020 21:16
@PureWeen PureWeen added p/UWP and removed DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. labels Mar 9, 2020
@PureWeen PureWeen marked this pull request as ready for review March 9, 2020 21:17
@PureWeen PureWeen moved this from In Progress to In Review in vCurrent (4.8.0) Mar 9, 2020
@samhouts samhouts moved this from In Review to In Progress in vCurrent (4.8.0) Mar 9, 2020
@samhouts samhouts removed this from In Progress in vCurrent (4.8.0) Mar 9, 2020
@samhouts samhouts added this to In Review in v4.6.0 Mar 9, 2020
@samhouts samhouts added this to In Review in Shell Mar 10, 2020
@PureWeen PureWeen added the blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. label Mar 20, 2020
@PureWeen PureWeen added the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Mar 24, 2020
@samhouts samhouts moved this from In Review to In Progress in v4.6.0 Mar 24, 2020
@PureWeen PureWeen removed the DO-NOT-MERGE-!!! 🛑 This is in progress and needs to be updated before it can be merged. label Mar 24, 2020
@@ -62,8 +62,8 @@ public IList<string> StyleClass
if (_styleClass != null) {
_classStyleProperties = new List<BindableProperty> ();
foreach (var styleClass in _styleClass) {
var classStyleProperty = BindableProperty.Create ("ClassStyle", typeof(IList<Style>), typeof(VisualElement), default(IList<Style>),
propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable)._mergedStyle.OnClassStyleChanged());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed the cast because AFAICT _mergedStyle will always just be this

If that's not true then I think MergedStyle should be added to IStyleSelectable

{
IList<string> IStyleSelectable.Classes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the classes are defined on NavigeableElement I just moved the interface up to that class and removed from here to avoid confusion

@samhouts samhouts moved this from In Progress to In Review in v4.6.0 Mar 24, 2020
@samhouts samhouts merged commit 5ba5a2d into 4.6.0 Apr 3, 2020
Shell automation moved this from In Review to Done Apr 3, 2020
v4.6.0 automation moved this from In Review to Done Apr 3, 2020
@samhouts samhouts deleted the shell_flyout_styling branch April 3, 2020 21:52
@samhouts samhouts added this to the 4.6.0 milestone Apr 9, 2020
@samhouts samhouts added this to Done in Sprint 168 Apr 30, 2020
@samhouts samhouts removed this from Done in Shell May 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Sprint 168
  
Done
v4.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants