From ea33434819b79cf90887f5f4a0e5ea7c3772c864 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Mollazadeh Date: Sat, 1 Apr 2023 17:16:06 +0330 Subject: [PATCH 1/2] feat: Add Expander to Control Gallery --- src/Wpf.Ui.Gallery/App.xaml.cs | 8 +++ .../ViewModels/Pages/AllControlsViewModel.cs | 9 +++ .../Pages/Layout/ExpanderViewModel.cs | 13 ++++ .../Pages/Layout/LayoutViewModel.cs | 27 ++++++++ .../ViewModels/Windows/MainWindowViewModel.cs | 7 +++ .../DialogsAndFlyouts/ContentDialog.xaml.cs | 1 - .../Views/Pages/Layout/ExpanderPage.xaml | 61 +++++++++++++++++++ .../Views/Pages/Layout/ExpanderPage.xaml.cs | 19 ++++++ .../Views/Pages/Layout/LayoutPage.xaml | 27 ++++++++ .../Views/Pages/Layout/LayoutPage.xaml.cs | 23 +++++++ 10 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/ExpanderViewModel.cs create mode 100644 src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/LayoutViewModel.cs create mode 100644 src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml create mode 100644 src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml.cs create mode 100644 src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml create mode 100644 src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml.cs diff --git a/src/Wpf.Ui.Gallery/App.xaml.cs b/src/Wpf.Ui.Gallery/App.xaml.cs index f6fdf38ce..ee4c8bd15 100644 --- a/src/Wpf.Ui.Gallery/App.xaml.cs +++ b/src/Wpf.Ui.Gallery/App.xaml.cs @@ -13,6 +13,7 @@ using Wpf.Ui.Gallery.ViewModels.Pages.DateAndTime; using Wpf.Ui.Gallery.ViewModels.Pages.DialogsAndFlyouts; using Wpf.Ui.Gallery.ViewModels.Pages.Icons; +using Wpf.Ui.Gallery.ViewModels.Pages.Layout; using Wpf.Ui.Gallery.ViewModels.Pages.Media; using Wpf.Ui.Gallery.ViewModels.Pages.Navigation; using Wpf.Ui.Gallery.ViewModels.Pages.StatusAndInfo; @@ -25,6 +26,7 @@ using Wpf.Ui.Gallery.Views.Pages.DateAndTime; using Wpf.Ui.Gallery.Views.Pages.DialogsAndFlyouts; using Wpf.Ui.Gallery.Views.Pages.Icons; +using Wpf.Ui.Gallery.Views.Pages.Layout; using Wpf.Ui.Gallery.Views.Pages.Media; using Wpf.Ui.Gallery.Views.Pages.Navigation; using Wpf.Ui.Gallery.Views.Pages.Samples; @@ -130,6 +132,12 @@ public partial class App : Application services.AddTransient(); services.AddTransient(); + // Layout + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + // Web View services.AddTransient(); services.AddTransient(); diff --git a/src/Wpf.Ui.Gallery/ViewModels/Pages/AllControlsViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Pages/AllControlsViewModel.cs index 0a7e6f71e..c27d84292 100644 --- a/src/Wpf.Ui.Gallery/ViewModels/Pages/AllControlsViewModel.cs +++ b/src/Wpf.Ui.Gallery/ViewModels/Pages/AllControlsViewModel.cs @@ -322,6 +322,15 @@ public partial class AllControlsViewModel : ObservableObject Icon = SymbolRegular.TextFont24, Description = "Control displaying a single font glyph.", Link = "FontIcon" + }, + #if DEBUG + new() + { + Name = "Expander", + Icon = SymbolRegular.Code24, + Description = "Expander control.", + Link = "Expander" } + #endif }; } diff --git a/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/ExpanderViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/ExpanderViewModel.cs new file mode 100644 index 000000000..267df3280 --- /dev/null +++ b/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/ExpanderViewModel.cs @@ -0,0 +1,13 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +namespace Wpf.Ui.Gallery.ViewModels.Pages.Layout; + +public partial class ExpanderViewModel : ObservableObject +{ + public ExpanderViewModel() + { + } +} diff --git a/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/LayoutViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/LayoutViewModel.cs new file mode 100644 index 000000000..ef4968737 --- /dev/null +++ b/src/Wpf.Ui.Gallery/ViewModels/Pages/Layout/LayoutViewModel.cs @@ -0,0 +1,27 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + +using System.Collections.Generic; +using System.Collections.ObjectModel; +using CommunityToolkit.Mvvm.ComponentModel; +using Wpf.Ui.Common; +using Wpf.Ui.Gallery.Models; + +namespace Wpf.Ui.Gallery.ViewModels.Pages.Layout; + +public partial class LayoutViewModel : ObservableObject +{ + [ObservableProperty] + private ICollection _navigationCards = new ObservableCollection + { + new() + { + Name = "Expander", + Icon = SymbolRegular.Code24, + Description = "Expander control.", + Link = "Expander" + }, + }; +} diff --git a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs index 64af8f36c..9329b1732 100644 --- a/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs +++ b/src/Wpf.Ui.Gallery/ViewModels/Windows/MainWindowViewModel.cs @@ -13,6 +13,7 @@ using Wpf.Ui.Gallery.Views.Pages.DateAndTime; using Wpf.Ui.Gallery.Views.Pages.DialogsAndFlyouts; using Wpf.Ui.Gallery.Views.Pages.Icons; +using Wpf.Ui.Gallery.Views.Pages.Layout; using Wpf.Ui.Gallery.Views.Pages.Media; using Wpf.Ui.Gallery.Views.Pages.Navigation; using Wpf.Ui.Gallery.Views.Pages.StatusAndInfo; @@ -80,6 +81,12 @@ public MainWindowViewModel(IServiceProvider serviceProvider) new NavigationViewItem { Content = "Flyout", TargetPageType = typeof(FlyoutPage) }, new NavigationViewItem { Content = "MessageBox", TargetPageType = typeof(MessageBoxPage) }, }}, +#if DEBUG + new NavigationViewItem { Content = "Layout", Icon = new SymbolIcon { Symbol = SymbolRegular.News24}, TargetPageType = typeof(LayoutPage), MenuItems = new ObservableCollection() + { + new NavigationViewItem { Content = "Expander", TargetPageType = typeof(ExpanderPage) }, + }}, +#endif new NavigationViewItem {Content = "Media", Icon = new SymbolIcon { Symbol = SymbolRegular.PlayCircle24 }, TargetPageType = typeof(MediaPage), MenuItems = new ObservableCollection { new NavigationViewItem { Content = "Image", TargetPageType = typeof(ImagePage) }, diff --git a/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/ContentDialog.xaml.cs b/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/ContentDialog.xaml.cs index 9ac821899..5e96bf7e0 100644 --- a/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/ContentDialog.xaml.cs +++ b/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/ContentDialog.xaml.cs @@ -15,7 +15,6 @@ public ContentDialogPage(ContentDialogViewModel viewModel) { ViewModel = viewModel; DataContext = viewModel; - DataContext = viewModel; InitializeComponent(); } diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml b/src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml new file mode 100644 index 000000000..c14403d31 --- /dev/null +++ b/src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml @@ -0,0 +1,61 @@ + + + https://github.com/lepoco/wpfui/blob/development/src/Wpf.Ui/Styles/Controls/Expander.xaml + https://github.com/lepoco/wpfui/blob/development/src/Wpf.Ui/Controls/Expander.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml.cs b/src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml.cs new file mode 100644 index 000000000..1f96c02fb --- /dev/null +++ b/src/Wpf.Ui.Gallery/Views/Pages/Layout/ExpanderPage.xaml.cs @@ -0,0 +1,19 @@ +using Wpf.Ui.Controls.Navigation; +using Wpf.Ui.Gallery.ViewModels.Pages.Layout; + +namespace Wpf.Ui.Gallery.Views.Pages.Layout +{ + /// + /// Interaction logic for Expander.xaml + /// + public partial class ExpanderPage : INavigableView + { + public ExpanderPage(ExpanderViewModel viewModel) + { + InitializeComponent(); + ViewModel = viewModel; + } + + public ExpanderViewModel ViewModel { get; } + } +} diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml b/src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml new file mode 100644 index 000000000..debc9bdc2 --- /dev/null +++ b/src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml @@ -0,0 +1,27 @@ + + + + + + diff --git a/src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml.cs b/src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml.cs new file mode 100644 index 000000000..8680ca0c3 --- /dev/null +++ b/src/Wpf.Ui.Gallery/Views/Pages/Layout/LayoutPage.xaml.cs @@ -0,0 +1,23 @@ +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. +// All Rights Reserved. + + +using Wpf.Ui.Controls.Navigation; +using Wpf.Ui.Gallery.ViewModels.Pages.Layout; + +namespace Wpf.Ui.Gallery.Views.Pages.Layout; + +public partial class LayoutPage : INavigableView +{ + public LayoutViewModel ViewModel { get; } + + public LayoutPage(LayoutViewModel viewModel) + { + ViewModel = viewModel; + DataContext = this; + + InitializeComponent(); + } +} From 7d83ce66beded7df2de9efa926e222a41f65b4de Mon Sep 17 00:00:00 2001 From: Mohammad Amin Mollazadeh Date: Sat, 1 Apr 2023 17:29:57 +0330 Subject: [PATCH 2/2] fix(Expander): update animation to match WinUI --- .../AnimationFactorToValueConverter.cs | 22 ++++ src/Wpf.Ui/Styles/Controls/Expander.xaml | 119 ++++++++++-------- 2 files changed, 90 insertions(+), 51 deletions(-) create mode 100644 src/Wpf.Ui/Converters/AnimationFactorToValueConverter.cs diff --git a/src/Wpf.Ui/Converters/AnimationFactorToValueConverter.cs b/src/Wpf.Ui/Converters/AnimationFactorToValueConverter.cs new file mode 100644 index 000000000..b36b57c74 --- /dev/null +++ b/src/Wpf.Ui/Converters/AnimationFactorToValueConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace Wpf.Ui.Converters; + +public class AnimationFactorToValueConverter : IMultiValueConverter +{ + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values[0] is not double completeValue) return 0.0; + if (values[1] is not double factor) return 0.0; + if (parameter is "negative") factor = -factor; + + return factor * completeValue; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/src/Wpf.Ui/Styles/Controls/Expander.xaml b/src/Wpf.Ui/Styles/Controls/Expander.xaml index 0d52dc032..224ee1208 100644 --- a/src/Wpf.Ui/Styles/Controls/Expander.xaml +++ b/src/Wpf.Ui/Styles/Controls/Expander.xaml @@ -12,6 +12,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:Wpf.Ui.Controls" + xmlns:converters="clr-namespace:Wpf.Ui.Converters" xmlns:iconElements="clr-namespace:Wpf.Ui.Controls.IconElements" xmlns:system="clr-namespace:System;assembly=System.Runtime"> @@ -106,19 +107,24 @@ - - - - - - + + + - + + + + + + + + + - + + + BorderThickness="1,0,1,1" + CornerRadius="0,0,4,4" + Visibility="Collapsed"> - - - + + 0.0 + + + + + + + + + + + - + + - + - - + + + + + + + - - + + + + + + + + - - - - - + + + + +