diff --git a/.github/workflows/get_versions.yml b/.github/workflows/get_versions.yml index 4a6f9110e5..c916fd7535 100644 --- a/.github/workflows/get_versions.yml +++ b/.github/workflows/get_versions.yml @@ -2,7 +2,7 @@ name: Setup Versions on: workflow_call: - inputs: + inputs: is-full-release: required: false type: boolean diff --git a/src/MainDemo.Wpf/Domain/MainWindowViewModel.cs b/src/MainDemo.Wpf/Domain/MainWindowViewModel.cs index 64ec7192c5..12e4238fc8 100644 --- a/src/MainDemo.Wpf/Domain/MainWindowViewModel.cs +++ b/src/MainDemo.Wpf/Domain/MainWindowViewModel.cs @@ -1,132 +1,133 @@ using System.Collections.ObjectModel; using System.ComponentModel; using System.Configuration; +using System.Reflection; using System.Windows.Data; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using MaterialDesignColors; using MaterialDesignDemo.Shared.Domain; using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf.Transitions; namespace MaterialDesignDemo.Domain; -public class MainWindowViewModel : ViewModelBase +public partial class MainWindowViewModel : ObservableObject { public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, string? startupPage) { - DemoItems = new ObservableCollection(new[] - { + DemoItems = + [ new DemoItem( "Home", typeof(Home), - new[] - { + [ new DocumentationLink( DocumentationLinkType.Wiki, $"{ConfigurationManager.AppSettings["GitHub"]}/wiki", "WIKI"), DocumentationLink.DemoPageLink() - } + ] ) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled - } - }); - - foreach (var item in GenerateDemoItems(snackbarMessageQueue).OrderBy(i => i.Name)) - { - DemoItems.Add(item); - } + }, + .. GenerateDemoItems(snackbarMessageQueue).OrderBy(i => i.Name), + ]; SelectedItem = DemoItems.FirstOrDefault(di => string.Equals(di.Name, startupPage, StringComparison.CurrentCultureIgnoreCase)) ?? DemoItems.First(); _demoItemsView = CollectionViewSource.GetDefaultView(DemoItems); _demoItemsView.Filter = DemoItemsFilter; + LoadVersions(); + } - HomeCommand = new AnotherCommandImplementation( - _ => - { - SearchKeyword = string.Empty; - SelectedIndex = 0; - }); - - MovePrevCommand = new AnotherCommandImplementation( - _ => - { - if (!string.IsNullOrWhiteSpace(SearchKeyword)) - SearchKeyword = string.Empty; - - SelectedIndex--; - }, - _ => SelectedIndex > 0); + private readonly ICollectionView _demoItemsView; - MoveNextCommand = new AnotherCommandImplementation( - _ => - { - if (!string.IsNullOrWhiteSpace(SearchKeyword)) - SearchKeyword = string.Empty; + [ObservableProperty] + private string? _searchKeyword; - SelectedIndex++; - }, - _ => SelectedIndex < DemoItems.Count - 1); + partial void OnSearchKeywordChanged(string? oldValue, string? newValue) + { + _demoItemsView.Refresh(); } - private readonly ICollectionView _demoItemsView; - private DemoItem? _selectedItem; - private int _selectedIndex; - private string? _searchKeyword; - private bool _controlsEnabled = true; + [ObservableProperty] + private string? _nugetVersions; - public string? SearchKeyword + private void LoadVersions() { - get => _searchKeyword; - set + string? mdixVersion = GetVersion("MDIXVersion"); + string? mdixColorsVersion = GetVersion("MDIXColorsVersion"); + + NugetVersions = $""" + MDIX: {mdixVersion} + MDIX Colors: {mdixColorsVersion} + """; + + static string? GetVersion(string attributeKey) { - if (SetProperty(ref _searchKeyword, value)) - { - _demoItemsView.Refresh(); - } + return typeof(T).Assembly + .GetCustomAttributes() + .SingleOrDefault(x => x.Key == attributeKey)?.Value; } } public ObservableCollection DemoItems { get; } - public DemoItem? SelectedItem + + [ObservableProperty] + private DemoItem? _selectedItem; + + [ObservableProperty] + [NotifyCanExecuteChangedFor(nameof(MoveNextCommand))] + [NotifyCanExecuteChangedFor(nameof(MovePrevCommand))] + private int _selectedIndex; + + [ObservableProperty] + private bool _controlsEnabled = true; + + [RelayCommand] + private void OnHome() { - get => _selectedItem; - set => SetProperty(ref _selectedItem, value); + SearchKeyword = string.Empty; + SelectedIndex = 0; } - public int SelectedIndex + [RelayCommand(CanExecute = nameof(CanMovePrevious))] + private void OnMovePrev() { - get => _selectedIndex; - set => SetProperty(ref _selectedIndex, value); + if (!string.IsNullOrWhiteSpace(SearchKeyword)) + SearchKeyword = string.Empty; + + SelectedIndex--; } - public bool ControlsEnabled + private bool CanMovePrevious() => SelectedIndex > 0; + + [RelayCommand(CanExecute = nameof(CanMoveNext))] + private void OnMoveNext() { - get => _controlsEnabled; - set => SetProperty(ref _controlsEnabled, value); + if (!string.IsNullOrWhiteSpace(SearchKeyword)) + SearchKeyword = string.Empty; + + SelectedIndex++; } - public AnotherCommandImplementation HomeCommand { get; } - public AnotherCommandImplementation MovePrevCommand { get; } - public AnotherCommandImplementation MoveNextCommand { get; } + private bool CanMoveNext() => SelectedIndex < DemoItems.Count - 1; private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue snackbarMessageQueue) { - if (snackbarMessageQueue is null) - throw new ArgumentNullException(nameof(snackbarMessageQueue)); - yield return new DemoItem( "Palette", typeof(PaletteSelector), - new[] - { + [ DocumentationLink.WikiLink("Brush-Names", "Brushes"), DocumentationLink.WikiLink("Custom-Palette-Hues", "Custom Palettes"), DocumentationLink.WikiLink("Swatches-and-Recommended-Colors", "Swatches"), DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model","Domain"), DocumentationLink.ApiLink() - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled }; @@ -134,58 +135,53 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "ColorTool", typeof(ColorTool), - new[] - { + [ DocumentationLink.WikiLink("Brush-Names", "Brushes"), DocumentationLink.WikiLink("Custom-Palette-Hues", "Custom Palettes"), DocumentationLink.WikiLink("Swatches-and-Recommended-Colors", "Swatches"), DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model","Domain"), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "Button", typeof(Buttons), - new[] - { + [ DocumentationLink.WikiLink("Button-Styles", "Buttons"), DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model", "Domain"), DocumentationLink.StyleLink("Button"), DocumentationLink.StyleLink("PopupBox"), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "Toggle", typeof(Toggles), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("ToggleButton"), DocumentationLink.StyleLink("CheckBox"), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "RatingBar", typeof(RatingBar), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("RatingBar"), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "Field", typeof(Fields), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("TextBox") - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, }; @@ -193,30 +189,27 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Fields line up", typeof(FieldsLineUp), - new[] - { + [ DocumentationLink.DemoPageLink() - }); + ]); yield return new DemoItem( "ComboBox", typeof(ComboBoxes), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("ComboBox") - }); + ]); yield return new DemoItem( "Picker", typeof(Pickers), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Clock"), DocumentationLink.StyleLink("DatePicker"), DocumentationLink.ApiLink() - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, }; @@ -224,30 +217,27 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Slider", typeof(Sliders), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Slider") - }); + ]); yield return new DemoItem( "Chip", typeof(Chips), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Chip"), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "Typography", typeof(Typography), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("TextBlock") - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto }; @@ -255,12 +245,11 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Card", typeof(Cards), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Card"), DocumentationLink.ApiLink() - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled }; @@ -268,12 +257,11 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Icons", typeof(IconPack), - new[] - { + [ DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model", "Domain"), DocumentationLink.ApiLink() - }, + ], new IconPackViewModel(snackbarMessageQueue)) { //The icons view handles its own scrolling @@ -284,22 +272,20 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "ColorZone", typeof(ColorZones), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "List", typeof(Lists), - new[] - { + [ DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model", "Domain"), DocumentationLink.StyleLink("ListBox"), DocumentationLink.StyleLink("ListView") - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, }; @@ -307,49 +293,44 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Tab", typeof(Tabs), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("TabControl") - }); + ]); yield return new DemoItem( "Tree", typeof(Trees), - new[] - { + [ DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model", "Domain"), DocumentationLink.StyleLink("TreeView") - }); + ]); yield return new DemoItem( "DataGrid", typeof(DataGrids), - new[] - { + [ DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model", "Domain"), DocumentationLink.StyleLink("DataGrid") - }); + ]); yield return new DemoItem( "Expander", typeof(Expander), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Expander") - }); + ]); yield return new DemoItem( "GroupBox", typeof(GroupBoxes), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("GroupBox") - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, }; @@ -357,30 +338,27 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Menu & ToolBar", typeof(MenusAndToolBars), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Menu"), DocumentationLink.StyleLink("ToolBar") - }); + ]); yield return new DemoItem( "Progress Indicator", typeof(Progress), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("ProgressBar") - }); + ]); yield return new DemoItem( "NavigationRail", typeof(NavigationRail), - new[] - { + [ DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.StyleLink("TabControl"), - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, }; @@ -388,13 +366,12 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Dialog", typeof(Dialogs), - new[] - { + [ DocumentationLink.WikiLink("Dialogs", "Dialogs"), DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.DemoPageLink("Demo View Model", "Domain"), DocumentationLink.ApiLink() - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto }; @@ -402,23 +379,21 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Drawer", typeof(Drawers), - new[] - { + [ DocumentationLink.DemoPageLink("Demo View"), DocumentationLink.ApiLink() - }); + ]); yield return new DemoItem( "Snackbar", typeof(Snackbars), - new[] - { + [ DocumentationLink.WikiLink("Snackbar", "Snackbar"), DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Snackbar"), DocumentationLink.ApiLink(), DocumentationLink.ApiLink() - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto }; @@ -426,24 +401,22 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Transition", typeof(Transitions), - new[] - { + [ DocumentationLink.WikiLink("Transitions", "Transitions"), DocumentationLink.DemoPageLink(), DocumentationLink.ApiLink("Transitions"), DocumentationLink.ApiLink("Transitions"), DocumentationLink.ApiLink("Transitions"), - }); + ]); yield return new DemoItem( "Elevation", typeof(Elevation), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("Shadows"), DocumentationLink.SpecsLink("https://material.io/design/environment/elevation.html", "Elevation") - }) + ]) { HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, }; @@ -451,11 +424,10 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "Smart Hint", typeof(SmartHint), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("SmartHint"), - }) + ]) { //The smart hint view handles its own scrolling HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled, @@ -465,30 +437,35 @@ private static IEnumerable GenerateDemoItems(ISnackbarMessageQueue sna yield return new DemoItem( "PopupBox", typeof(PopupBox), - new[] - { + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink("PopupBox"), - }); + ]); - yield return new DemoItem(nameof(NumericUpDown), typeof(NumericUpDown), new[] - { + yield return new DemoItem(nameof(NumericUpDown), typeof(NumericUpDown), + [ DocumentationLink.DemoPageLink(), DocumentationLink.StyleLink(nameof(NumericUpDown)), DocumentationLink.ApiLink(), DocumentationLink.ApiLink(), DocumentationLink.ApiLink() - }); + ]); } private bool DemoItemsFilter(object obj) { - if (string.IsNullOrWhiteSpace(_searchKeyword)) + string? searchKeyword = SearchKeyword; + + if (string.IsNullOrWhiteSpace(searchKeyword)) { return true; } return obj is DemoItem item - && item.Name.ToLower().Contains(_searchKeyword!.ToLower()); +#if NET6_0_OR_GREATER + && item.Name.Contains(searchKeyword, StringComparison.OrdinalIgnoreCase); +#else + && item.Name.IndexOf(searchKeyword, StringComparison.OrdinalIgnoreCase) >= 0; +#endif } } diff --git a/src/MainDemo.Wpf/MainWindow.xaml b/src/MainDemo.Wpf/MainWindow.xaml index 598b362250..d88dbb49c5 100644 --- a/src/MainDemo.Wpf/MainWindow.xaml +++ b/src/MainDemo.Wpf/MainWindow.xaml @@ -186,6 +186,11 @@