Skip to content

Commit

Permalink
#33 allow override side menu behave (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmidID authored Jul 10, 2024
1 parent 44f6ae7 commit 9ccf014
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/AvaloniaInside.Shell/NavigationBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void SetHeader(AvaloniaObject element, object parameter) =>

#endregion

#region Hide
#region Visible

public static readonly AttachedProperty<bool> VisibleProperty =
AvaloniaProperty.RegisterAttached<NavigationBar, AvaloniaObject, bool>("Visible", defaultValue: true);
Expand Down Expand Up @@ -240,10 +240,10 @@ protected virtual void UpdateItems(object view, ContentControl itemPresenter)

if (itemPresenter.Content is StyledElement elementContent)
elementContent.DataContext = element.DataContext ?? element;

return;
}
}

itemPresenter.Content = view;
}

Expand Down
24 changes: 23 additions & 1 deletion src/AvaloniaInside.Shell/ShellView.SideMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public partial class ShellView

public double SideMenuSize => ScreenSize == ScreenSizeType.Small ? DesiredSize.Width - 35 : DefaultSideMenuSize;


public static readonly StyledProperty<double> DefaultSideMenuSizeProperty = AvaloniaProperty.Register<ShellView,double>(nameof(DefaultSideMenuSize), 250);

public double DefaultSideMenuSize
Expand Down Expand Up @@ -233,6 +232,24 @@ public SideMenuItem? SideMenuSelectedItem

#endregion

#region Attached properties

#region OverrideSideMenuBehave

public static readonly AttachedProperty<SideMenuBehaveType?> OverrideSideMenuBehaveProperty =
AvaloniaProperty.RegisterAttached<ShellView, AvaloniaObject, SideMenuBehaveType?>("OverrideSideMenuBehave",
defaultValue: null);

public static SideMenuBehaveType? GetOverrideSideMenuBehave(AvaloniaObject element) =>
element.GetValue(OverrideSideMenuBehaveProperty);

public static void SetOverrideSideMenuBehave(AvaloniaObject element, SideMenuBehaveType? parameter) =>
element.SetValue(OverrideSideMenuBehaveProperty, parameter);

#endregion

#endregion

#region Behavior

protected virtual Task MenuActionAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -273,6 +290,11 @@ protected virtual void UpdateSideMenu()

private SideMenuBehaveType GetCurrentBehave()
{
var view = this._contentView?.CurrentView;

if (view is StyledElement element && GetOverrideSideMenuBehave(element) is { } overrideBehave)
return overrideBehave;

return ScreenSize switch
{
ScreenSizeType.Small => SmallScreenSideMenuBehave,
Expand Down
1 change: 1 addition & 0 deletions src/AvaloniaInside.Shell/ShellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public async Task PushViewAsync(object view,
await (_contentView?.PushViewAsync(view, navigateType, cancellationToken) ?? Task.CompletedTask);
SelectSideMenuItem();
UpdateBindings();
UpdateSideMenu();
}

public async Task RemoveViewAsync(object view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="ShellExample.Views.WelcomeView"
NavigationBar.Visible="False">
NavigationBar.Visible="False"
ShellView.OverrideSideMenuBehave="Removed">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Spacing="14">
<TextBlock Text="Welcome to AvaloniaInside" FontSize="18" HorizontalAlignment="Center"></TextBlock>
Expand Down

0 comments on commit 9ccf014

Please sign in to comment.