add containter for header + set default window size

pull/19/head
Alexandre Agostinho 2 years ago
parent 251b6ececf
commit e695efac91

@ -1,11 +1,36 @@
namespace Views
using Microsoft.UI;
using Windows.Graphics;
#if WINDOWS
//using Microsoft.UI;
using Microsoft.UI.Windowing;
//using Windows.Graphics;
#endif
namespace Views
{
public partial class App : Application
{
const int WindowWidth = 1200;
const int WindowHeight = 800;
public App()
{
InitializeComponent();
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{
#if WINDOWS
var mauiWindow = handler.VirtualView;
var nativeWindow = handler.PlatformView;
nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif
});
MainPage = new AppShell();
Application.Current.UserAppTheme = AppTheme.Light;
}

@ -8,10 +8,57 @@
Shell.FlyoutBehavior="Flyout"
Shell.NavBarIsVisible="False">
<Shell.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="20, *" Padding="10">
<Image Source="{Binding Icon}"/>
<Label Grid.Column="1" Text="{Binding Title}"
TextColor="White" FontAttributes="Bold"
Padding="20, 0"/>
</Grid>
</DataTemplate>
</Shell.ItemTemplate>
<Shell.FlyoutHeader>
<VerticalStackLayout>
<ImageButton Source="person_default.png"
BackgroundColor="{StaticResource Secondary}"
WidthRequest="100" HeightRequest="100"
CornerRadius="50" Margin="0, 20, 0, 0"
IsEnabled="False"/>
<Button Text="Connection" ImageSource="login_icon.png"
MaximumHeightRequest="20" Margin="15, 15, 15, 60"/>
</VerticalStackLayout>
</Shell.FlyoutHeader>
<FlyoutItem Title="Suggestions" Icon="assistant_icon.png">
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:Home}"
Route="MainPage" />
Route="Home"/>
</FlyoutItem>
<FlyoutItem Title="Entrées" Icon="flatware_icon.png">
<ShellContent
ContentTemplate="{DataTemplate local:Home}"
Route="Home"/>
</FlyoutItem>
<FlyoutItem Title="Plats" Icon="room_service_icon.png">
<ShellContent
ContentTemplate="{DataTemplate local:Home}"
Route="Home"/>
</FlyoutItem>
<FlyoutItem Title="Desserts" Icon="coffee_icon.png">
<ShellContent
ContentTemplate="{DataTemplate local:Home}"
Route="Home"/>
</FlyoutItem>
<Shell.FlyoutFooter>
<VerticalStackLayout>
<Button Text="Déconnexion" ImageSource="logout_icon.png"
MaximumHeightRequest="20" Margin="15"
IsVisible="False"/>
</VerticalStackLayout>
</Shell.FlyoutFooter>
</Shell>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Views"
x:Class="Views.ContainerWithHeader"
x:Name="root">
<Grid RowDefinitions="50, *">
<local:CustomHeader
HeightRequest="80"
VerticalOptions="Start"
Padding="10, 0"/>
<ContentView
Grid.Row="1"
Content="{Binding MyContent, Source={x:Reference root}}"/>
</Grid>
</ContentView>

@ -0,0 +1,18 @@
namespace Views;
public partial class ContainerWithHeader : ContentView
{
public ContainerWithHeader()
{
InitializeComponent();
}
public static BindableProperty MyContentProperty =
BindableProperty.Create("MyContent", typeof(View), typeof(ContainerWithHeader), new Grid());
public View MyContent
{
get => (View)GetValue(MyContentProperty);
set => SetValue(MyContentProperty, value);
}
}

@ -2,19 +2,18 @@
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.CustomHeader"
BackgroundColor="LawnGreen">
BackgroundColor="{StaticResource Primary}">
<Grid ColumnDefinitions="30, *, 30">
<ImageButton Source="list_icon.png"
MaximumHeightRequest="20"
MaximumWidthRequest="20"
VerticalOptions="Center"/>
<Label Text="Mon app trop géniale"
FontAttributes="Bold"/>
<ImageButton Source="home_icon.png"
MaximumHeightRequest="20"
MaximumWidthRequest="20"
<Grid ColumnDefinitions="50, *">
<ImageButton Source="list_icon.png" Clicked="ImageButton_Clicked"
MaximumHeightRequest="20" MaximumWidthRequest="20"
VerticalOptions="Center"/>
<Label Text="Mon app trop géniale" Grid.Column="1"
FontAttributes="Bold" FontSize="24" Margin="20, 0, 0, 0"
VerticalOptions="Center" HorizontalOptions="Start"/>
</Grid>
</ContentView>

@ -6,4 +6,9 @@ public partial class CustomHeader : ContentView
{
InitializeComponent();
}
private void ImageButton_Clicked(object sender, EventArgs e)
{
(App.Current.MainPage as Shell).FlyoutIsPresented ^= true;
}
}

@ -2,49 +2,18 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:local="clr-namespace:CustomHeader"
x:Class="Views.Home"
Title="Mon app trop géniale">
xmlns:local="clr-namespace:Views"
x:Class="Views.Home">
<local:ContainerWithHeader>
<local:ContainerWithHeader.MyContent>
<!--<toolkit:DockLayout
HorizontalSpacing="20">-->
<!-- Aux menu -->
<!--<StackLayout toolkit:DockLayout.DockPosition="Left"
WidthRequest="250"
BackgroundColor="{StaticResource Tertiary}">
<ImageButton Source="person_default.png"
BackgroundColor="{StaticResource Secondary}"
WidthRequest="100" HeightRequest="100"
CornerRadius="50" Margin="0, 40, 0, 0"
HorizontalOptions="Fill"
VerticalOptions="Fill"
IsEnabled="False"/>
<Button Text="se connecter" TextColor="{StaticResource Black}"
BackgroundColor="{StaticResource Primary}"
CornerRadius="5"
Margin="15, 40"/>
<Button Text="Recherche" Style="{StaticResource button1}"/>
<Entry Text="Mot-clés" FontAttributes="Italic"
Margin="10, 0, 10, 30"/>
<Button Text="Entrées" Style="{StaticResource button1}"/>
<Button Text="Plats" Style="{StaticResource button1}"/>
<Button Text="Desserts" Style="{StaticResource button1}"/>
</StackLayout>-->
<!-- Master recipes -->
<ScrollView>
<StackLayout>
<Label Text="Suggestions" TextColor="{StaticResource Secondary}"
FontSize="32" FontAttributes="Bold" Padding="15"/>
<!-- Master recipes -->
<FlexLayout toolkit:DockLayout.DockPosition="None"
Margin="0, 15"
Wrap="Wrap"
@ -70,7 +39,7 @@
</StackLayout>
</ScrollView>
<!--</toolkit:DockLayout>-->
</local:ContainerWithHeader.MyContent>
</local:ContainerWithHeader>
</ContentPage>

@ -53,4 +53,19 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="CustomHeader.xaml.cs">
<DependentUpon>CustomHeader.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="ContainerWithHeader.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="CustomHeader.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>
</Project>

Loading…
Cancel
Save