整理控件库

This commit is contained in:
GG Z
2025-05-05 17:04:06 +08:00
parent 74532b77be
commit 3eaad7566e
283 changed files with 2156 additions and 17846 deletions

View File

@@ -1,12 +1,30 @@
using System.Windows.Controls;
using WPFluent.Gallery.ControlsLookup;
using WPFluent.Gallery.Models;
using WPFluent.Gallery.Views.Pages;
namespace WPFluent.Gallery.ViewModels.Pages;
public class Grade
{
public string GradeLevel { get; set; }
public List<Student> Students { get; set; } = [];
}
public class Student
{
public int ID { get; set; }
public string Name { get; set; }
public string Class { get; set; }
}
public partial class BasicInputViewModel : ViewModel
{
public BasicInputViewModel()
{
GenerateTreeViewItem();
}
[ObservableProperty]
private ICollection<NavigationCard> navigationCards = new ObservableCollection<NavigationCard>(
ControlPages
@@ -19,135 +37,52 @@ public partial class BasicInputViewModel : ViewModel
PageType = x.PageType,
})
);
#region Anchor
[ObservableProperty]
private bool _isAnchorEnabled = true;
[RelayCommand]
private void OnAnchorCheckboxChecked(object sender)
private void ButtonClick()
{
if (sender is not CheckBox checkbox)
{
return;
}
IsAnchorEnabled = !(checkbox?.IsChecked ?? false);
Toast.Information("I am information message");
Toast.Error("I am error message");
Toast.Success("I am success message");
Toast.Warning("I am warning message");
Toast.Show(owner: null!, "I am any message", new ToastConfig());
}
public ObservableCollection<Grade> Grades { get; set; } = [];
#endregion
public ObservableCollection<Grade> SelectedItems { get; set; } = [];
#region Button
[ObservableProperty]
private bool _isSimpleButtonEnabled = true;
[ObservableProperty]
private bool _isUiButtonEnabled = true;
[RelayCommand]
private void OnSimpleButtonCheckboxChecked(object sender)
public void GenerateTreeViewItem()
{
if (sender is not CheckBox checkbox)
{
return;
}
IsSimpleButtonEnabled = !(checkbox?.IsChecked ?? false);
Grade item = new() { GradeLevel = "一年级" };
item.Students.Add(new() { Name = "学生11" });
item.Students.Add(new() { Name = "学生12" });
item.Students.Add(new() { Name = "学生13" });
Grade item1 = new() { GradeLevel = "二年级" };
item1.Students.Add(new() { Name = "学生21" });
item1.Students.Add(new() { Name = "学生22" });
Grades.Add(item);
Grades.Add(item1);
}
[RelayCommand]
private void OnUiButtonCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsUiButtonEnabled = !(checkbox?.IsChecked ?? false);
}
[ObservableProperty]
private bool _isToggleSwitchEnabled = true;
[RelayCommand]
private void OnToggleSwitchCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsToggleSwitchEnabled = !(checkbox?.IsChecked ?? false);
}
[ObservableProperty]
private bool _isToggleButtonEnabled = true;
[RelayCommand]
private void OnToggleButtonCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsToggleButtonEnabled = !(checkbox?.IsChecked ?? false);
}
#endregion
#region CheckBox
[ObservableProperty]
private bool? _selectAllCheckBoxChecked = null;
[ObservableProperty]
private bool _optionOneCheckBoxChecked = false;
[ObservableProperty]
private bool _optionTwoCheckBoxChecked = true;
[ObservableProperty]
private bool _optionThreeCheckBoxChecked = false;
[RelayCommand]
private void OnSelectAllChecked(object sender)
{
if (sender is not CheckBox checkBox)
{
return;
}
checkBox.IsChecked ??=
!OptionOneCheckBoxChecked || !OptionTwoCheckBoxChecked || !OptionThreeCheckBoxChecked;
if (checkBox.IsChecked == true)
{
OptionOneCheckBoxChecked = true;
OptionTwoCheckBoxChecked = true;
OptionThreeCheckBoxChecked = true;
}
else if (checkBox.IsChecked == false)
{
OptionOneCheckBoxChecked = false;
OptionTwoCheckBoxChecked = false;
OptionThreeCheckBoxChecked = false;
}
}
[RelayCommand]
private void OnSingleChecked(string option)
{
bool allChecked = OptionOneCheckBoxChecked && OptionTwoCheckBoxChecked && OptionThreeCheckBoxChecked;
bool allUnchecked =
!OptionOneCheckBoxChecked && !OptionTwoCheckBoxChecked && !OptionThreeCheckBoxChecked;
SelectAllCheckBoxChecked =
allChecked ? true
: allUnchecked ? false
: (bool?)null;
}
#endregion
private ObservableCollection<string> animals =
[
"Cat",
"Dog",
"Bear",
"Lion",
"Mouse",
"Horse",
"Rat",
"Elephant",
"Kangaroo",
"Lizard",
"Snake",
"Frog",
"Fish",
"Butterfly",
"Human",
"Cow",
"Bumble Bee"
];
#region ComboBox
@@ -180,108 +115,4 @@ public partial class BasicInputViewModel : ViewModel
];
#endregion
[ObservableProperty]
private bool _isHyperlinkEnabled = true;
[RelayCommand]
private void OnHyperlinkCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsHyperlinkEnabled = !(checkbox?.IsChecked ?? false);
}
[ObservableProperty]
private bool _isRadioButtonEnabled = true;
[RelayCommand]
private void OnRadioButtonCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsRadioButtonEnabled = !(checkbox?.IsChecked ?? false);
}
#region Rating
[ObservableProperty]
private bool _isFirstRatingEnabled = true;
[ObservableProperty]
private double _firstRatingValue = 1.5D;
[ObservableProperty]
private bool _isSecondRatingEnabled = true;
[ObservableProperty]
private double _secondRatingValue = 3D;
[RelayCommand]
private void OnFirstRatingCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsFirstRatingEnabled = !(checkbox?.IsChecked ?? false);
}
[RelayCommand]
private void OnSecondRatingCheckboxChecked(object sender)
{
if (sender is not CheckBox checkbox)
{
return;
}
IsSecondRatingEnabled = !(checkbox?.IsChecked ?? false);
}
#endregion
[ObservableProperty]
private int _simpleSliderValue = 0;
[ObservableProperty]
private int _rangeSliderValue = 500;
[ObservableProperty]
private int _marksSliderValue = 0;
[ObservableProperty]
private int _verticalSliderValue = 0;
[ObservableProperty]
private string _thumRateStateText = "Liked";
[ObservableProperty]
private string _thumRateStateCodeText = "<ui:ThumbRate State=\"Liked\" />";
private ThumbRateState _thumbRateState = ThumbRateState.Liked;
public ThumbRateState ThumbRateState
{
get => _thumbRateState;
set
{
ThumRateStateText = value switch
{
ThumbRateState.Liked => "Liked",
ThumbRateState.Disliked => "Disliked",
_ => "None",
};
ThumRateStateCodeText = $"<ui:ThumbRate State=\"{ThumRateStateText}\" />";
_ = SetProperty(ref _thumbRateState, value);
}
}
}

View File

@@ -1,29 +0,0 @@
// 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 WPFluent.Gallery.Helpers;
namespace WPFluent.Gallery.ViewModels.Pages;
public partial class DashboardViewModel(INavigationService navigationService) : ViewModel
{
[RelayCommand]
private void OnCardClick(string parameter)
{
if (string.IsNullOrWhiteSpace(parameter))
{
return;
}
Type? pageType = NameToPageTypeConverter.Convert(parameter);
if (pageType == null)
{
return;
}
_ = navigationService.Navigate(pageType);
}
}

View File

@@ -47,53 +47,6 @@ public partial class DialogsAndFlyoutsViewModel : ViewModel
_ = await uiMessageBox.ShowDialogAsync();
}
#region Snackbar
private ControlAppearance _snackbarAppearance = ControlAppearance.Secondary;
[ObservableProperty]
private int _snackbarTimeout = 2;
private int _snackbarAppearanceComboBoxSelectedIndex = 1;
public int SnackbarAppearanceComboBoxSelectedIndex
{
get => _snackbarAppearanceComboBoxSelectedIndex;
set
{
_ = SetProperty(ref _snackbarAppearanceComboBoxSelectedIndex, value);
UpdateSnackbarAppearance(value);
}
}
ISnackbarService snackbarService;
[RelayCommand]
private void OnOpenSnackbar(object sender)
{
snackbarService.Show(
"Don't Blame Yourself.",
"No Witcher's Ever Died In His Bed.",
_snackbarAppearance,
new SymbolIcon(SymbolRegular.Fluent24),
TimeSpan.FromSeconds(SnackbarTimeout)
);
}
private void UpdateSnackbarAppearance(int appearanceIndex)
{
_snackbarAppearance = appearanceIndex switch
{
1 => ControlAppearance.Secondary,
2 => ControlAppearance.Info,
3 => ControlAppearance.Success,
4 => ControlAppearance.Caution,
5 => ControlAppearance.Danger,
6 => ControlAppearance.Light,
7 => ControlAppearance.Dark,
8 => ControlAppearance.Transparent,
_ => ControlAppearance.Primary,
};
}
#endregion
[ObservableProperty]
private bool _isFlyoutOpen = false;
@@ -106,7 +59,7 @@ public partial class DialogsAndFlyoutsViewModel : ViewModel
}
}
#region ContentDialog
IContentDialogService contentDialogService;
ContentDialogService contentDialogService;
[ObservableProperty]
private string _dialogResultText = string.Empty;
@@ -114,7 +67,7 @@ public partial class DialogsAndFlyoutsViewModel : ViewModel
private async Task OnShowDialog(object content)
{
ContentDialogResult result = await contentDialogService.ShowSimpleDialogAsync(
new SimpleContentDialogCreateOptions()
new SimpleContentDialogOptions()
{
Title = "Save your work?",
Content = content,

View File

@@ -30,10 +30,10 @@ public partial class IconsViewModel : ViewModel
private bool _isIconFilled = false;
[ObservableProperty]
private List<DisplayableIcon> _iconsCollection = [];
private List<DisplayableIcon> iconsCollection = [];
[ObservableProperty]
private List<DisplayableIcon> _filteredIconsCollection = [];
private List<DisplayableIcon> filteredIconsCollection = [];
[ObservableProperty]
private List<string> _iconNames = [];

View File

@@ -3,6 +3,7 @@
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
using WPFluent.Extensions;
using WPFluent.Gallery.ControlsLookup;
using WPFluent.Gallery.Models;
using WPFluent.Gallery.Views.Pages;
@@ -23,4 +24,9 @@ public partial class LayoutViewModel : ViewModel
PageType = x.PageType,
})
);
[RelayCommand()]
private void ShowDialog()
{
MessageExtensions.ShowMessage();
}
}

View File

@@ -1,21 +0,0 @@
// 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 WPFluent.Gallery.ViewModels.Pages.Navigation;
public partial class MultilevelNavigationSample(INavigationService navigationService)
{
[RelayCommand]
private void NavigateForward(Type type)
{
_ = navigationService.NavigateWithHierarchy(type);
}
[RelayCommand]
private void NavigateBack()
{
_ = navigationService.GoBack();
}
}

View File

@@ -23,4 +23,17 @@ public partial class NavigationViewModel : ViewModel
PageType = x.PageType,
})
);
[ObservableProperty]
private List<string> strings = new List<string>()
{
"Navigation",
"NavigationPage",
"NavigationCard",
"NavigationViewModel",
"NavigationPage.xaml",
"NavigationPage.xaml.cs",
"ControlPages",
"GalleryPageAttribute",
"GalleryPage"
};
}

View File

@@ -12,7 +12,7 @@ using WPFluent.Extensions;
namespace WPFluent.Gallery.ViewModels.Pages;
public sealed partial class SettingsViewModel(INavigationService navigationService) : ViewModel
public sealed partial class SettingsViewModel() : ViewModel
{
private bool _isInitialized = false;
@@ -20,11 +20,7 @@ public sealed partial class SettingsViewModel(INavigationService navigationServi
private string _appVersion = string.Empty;
[ObservableProperty]
private ApplicationTheme _currentApplicationTheme = ApplicationTheme.Unknown;
[ObservableProperty]
private NavigationViewPaneDisplayMode _currentApplicationNavigationStyle =
NavigationViewPaneDisplayMode.Left;
private ThemeType _currentApplicationTheme = ThemeType.Unknow;
public override void OnNavigatedTo()
{
@@ -34,30 +30,23 @@ public sealed partial class SettingsViewModel(INavigationService navigationServi
}
}
partial void OnCurrentApplicationThemeChanged(ApplicationTheme oldValue, ApplicationTheme newValue)
partial void OnCurrentApplicationThemeChanged(ThemeType oldValue, ThemeType newValue)
{
ApplicationThemeManager.Apply(newValue);
ThemeManager.ChangeAppTheme(newValue);
}
partial void OnCurrentApplicationNavigationStyleChanged(
NavigationViewPaneDisplayMode oldValue,
NavigationViewPaneDisplayMode newValue
)
{
_ = navigationService.SetPaneDisplayMode(newValue);
}
private void InitializeViewModel()
{
CurrentApplicationTheme = ApplicationThemeManager.GetAppTheme();
CurrentApplicationTheme = ThemeManager.GetAppTheme();
AppVersion = $"{GetAssemblyVersion()}";
ApplicationThemeManager.Changed += OnThemeChanged;
ThemeManager.Changed += OnThemeChanged;
_isInitialized = true;
}
private void OnThemeChanged(ApplicationTheme currentApplicationTheme, Color systemAccent)
private void OnThemeChanged(ThemeType currentApplicationTheme, Color systemAccent)
{
// Update the theme if it has been changed elsewhere than in the settings.
if (CurrentApplicationTheme != currentApplicationTheme)

View File

@@ -41,4 +41,5 @@ public partial class TextViewModel : ViewModel
"Jamie",
"Alexzander",
};
}

View File

@@ -15,8 +15,8 @@ public partial class WindowsViewModel(WindowsProviderService windowsProviderServ
[ObservableProperty]
private WindowCard[] _windowCards =
[
new("FluentWindow", "Custom FluentWindow.", SymbolRegular.CodeBlock24, "FluentWindow"),
new("FluentWindowEx", "Custom FluentWindowEx.", SymbolRegular.ScanText24, "FluentWindowEx"),
new("FluentWindow", "Light FluentWindow.", SymbolRegular.CodeBlock24, "FluentWindow"),
new("FluentWindowEx", "Light FluentWindowEx.", SymbolRegular.ScanText24, "FluentWindowEx"),
new("FluentWindowWithTitleBar", "FluentWindow With TitleBar.", SymbolRegular.ScanText24, "FluentWindowWithTitleBar"),
];