Skip to content

Replace drawer with flyout #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CS/DrawerViewExample/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
x:Class="DrawerViewExample.App"
windows:Application.ImageDirectory="Assets">
<Application.Resources>

<local:BoolToDrawerBehaviorConverter x:Key="boolToDrawerBehaviorConverter"/>
</Application.Resources>
</Application>
4 changes: 0 additions & 4 deletions CS/DrawerViewExample/DrawerViewExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<MauiFont Include="Resources\Fonts\*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DevExpress.Maui.Navigation" Version="22.1.1-pre-*" />
</ItemGroup>

<PropertyGroup>
<UseInterpreter Condition="$(TargetFramework.Contains('-android'))">False</UseInterpreter>
</PropertyGroup>
Expand Down
78 changes: 34 additions & 44 deletions CS/DrawerViewExample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
<FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DrawerViewExample.MainPage"
xmlns:local="clr-namespace:DrawerViewExample"
xmlns:dxn="clr-namespace:DevExpress.Maui.Navigation;assembly=DevExpress.Maui.Navigation"

FlyoutLayoutBehavior="{Binding IsLandscapeOriented, Source={x:Reference page},
Converter={StaticResource boolToDrawerBehaviorConverter}}"
x:Name="page">
<ContentPage.Resources>
<local:BoolToDrawerBehaviorConverter x:Key="boolToDrawerBehaviorConverter"/>
</ContentPage.Resources>
<ContentPage.BindingContext>
<FlyoutPage.BindingContext>
<local:MainViewModel/>
</ContentPage.BindingContext>
<dxn:DrawerView x:Name="drawer"
DrawerBehavior="{Binding IsLandscapeOriented, Source={x:Reference page},
Converter={StaticResource boolToDrawerBehaviorConverter}}"
DrawerWidth="180"
DrawerShadowHeight="10"
DrawerShadowRadius="40"
DrawerShadowColor="#808080"
ScrimColor="#80000000">
<dxn:DrawerView.DrawerContent>
<Grid HeightRequest="800">
<ListView x:Name="carBrandList"
ItemsSource="{Binding CarModelsByBrand}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Padding="5" Text="{Binding BrandName}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</dxn:DrawerView.DrawerContent>
<dxn:DrawerView.MainContent>
<Grid HeightRequest="800">
<ListView BindingContext="{x:Reference carBrandList}"
ItemsSource="{Binding SelectedItem.CarModels}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Padding="5" Text="{Binding FullName}" />
</ViewCell>
</FlyoutPage.BindingContext>
<FlyoutPage.Flyout>
<ContentPage Title="About" IconImageSource="hamburger" WidthRequest="50">
<CollectionView x:Name="carBrandList"
ItemsSource="{Binding CarModelsByBrand}" SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Padding="5" Text="{Binding BrandName}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</dxn:DrawerView.MainContent>
</dxn:DrawerView>
</ContentPage>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage WidthRequest="50">
<x:Arguments>
<ContentPage>
<CollectionView BindingContext="{x:Reference carBrandList}"
ItemsSource="{Binding SelectedItem.CarModels}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Padding="5" Text="{Binding FullName}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
</FlyoutPage>
14 changes: 8 additions & 6 deletions CS/DrawerViewExample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using Microsoft.Maui.Controls;
using DevExpress.Maui.Navigation;
using System.Globalization;

namespace DrawerViewExample {
public partial class MainPage : ContentPage {
public partial class MainPage : FlyoutPage {
const string IsLandscapeOrientedPropertyName = "IsLandscapeOriented";

public static readonly BindableProperty IsLandscapeOrientedProperty = BindableProperty.Create(
Expand All @@ -18,13 +17,16 @@ public bool IsLandscapeOriented {
set => SetValue(IsLandscapeOrientedProperty, value);
}
public MainPage() {
InitializeComponent();
drawer.IsDrawerOpened = true;
InitializeComponent();
SizeChanged += OnSizeChanged;
carBrandList.SelectionChanged += OnSelectionChanged;
}
protected void OnSizeChanged(object sender, EventArgs args) {
IsLandscapeOriented = this.Width > this.Height;
}
void OnSelectionChanged(object sender, SelectionChangedEventArgs e) {
IsPresented = false;
}

protected override void OnAppearing() {
base.OnAppearing();
Expand All @@ -34,9 +36,9 @@ protected override void OnAppearing() {

class BoolToDrawerBehaviorConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if (targetType != typeof(DrawerBehavior)) return null;
if (targetType != typeof(FlyoutLayoutBehavior)) return null;
bool boolValue = (bool)value;
return boolValue ? DrawerBehavior.Split : DrawerBehavior.SlideOnTop;
return boolValue ? FlyoutLayoutBehavior.Split : FlyoutLayoutBehavior.Popover;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
Expand Down
4 changes: 1 addition & 3 deletions CS/DrawerViewExample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls.Hosting;
using DevExpress.Maui;
using Microsoft.Maui.Controls.Hosting;

namespace DrawerViewExample {
public static class MauiProgram {
public static MauiApp CreateMauiApp() {
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseDevExpress()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand Down
1 change: 1 addition & 0 deletions CS/DrawerViewExample/Resources/Images/hamburger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.