Исправление кнопок в просмотрщике

This commit is contained in:
2025-05-21 16:11:57 +04:00
parent 4d01b100d1
commit 96b4d6da31
4 changed files with 59 additions and 25 deletions
@@ -27,7 +27,7 @@
<Button
Width="25"
Margin="0,0,3,0"
Click="FirstButton_OnClick"
Command="{Binding FirstPageCommand}"
Content="&lt;&lt;"
DockPanel.Dock="Left"
IsEnabled="{Binding HasPrevious}" />
@@ -35,7 +35,7 @@
<Button
Width="25"
Margin="0,0,3,0"
Click="PreviousButton_OnClick"
Command="{Binding PreviousPageCommand}"
Content="&lt;"
DockPanel.Dock="Left"
IsEnabled="{Binding HasPrevious}" />
@@ -43,7 +43,7 @@
<Button
Width="25"
Margin="3,0,0,0"
Click="LastButton_OnClick"
Command="{Binding LastPageCommand}"
Content="&gt;&gt;"
DockPanel.Dock="Right"
IsEnabled="{Binding HasNext}" />
@@ -51,7 +51,7 @@
<Button
Width="25"
Margin="3,0,0,0"
Click="NextButton_OnClick"
Command="{Binding NextPageCommand}"
Content="&gt;"
DockPanel.Dock="Right"
IsEnabled="{Binding HasNext}" />
@@ -8,16 +8,6 @@ namespace Pf2eDataScrapper.WPF.EntityViewer.Component;
/// </summary>
internal partial class EntityListControl : System.Windows.Controls.UserControl
{
public EntityListViewModel? ViewModel
{
get => _viewModel;
set
{
_viewModel = value;
DataContext = ViewModel;
}
}
private EntityListViewModel? _viewModel;
public EntityListControl()
@@ -29,22 +19,22 @@ internal partial class EntityListControl : System.Windows.Controls.UserControl
private void FirstButton_OnClick(object sender, RoutedEventArgs e)
{
ViewModel?.FirstPage();
// DataContext?.FirstPage();
}
private void PreviousButton_OnClick(object sender, RoutedEventArgs e)
{
ViewModel?.PreviousPage();
//ViewModel?.PreviousPage();
}
private void NextButton_OnClick(object sender, RoutedEventArgs e)
{
ViewModel?.NextPage();
//ViewModel?.NextPage();
}
private void LastButton_OnClick(object sender, RoutedEventArgs e)
{
ViewModel?.LastPage();
//ViewModel?.LastPage();
}
private void TextBox_PreviewTextInput(
@@ -54,8 +54,8 @@ internal class StructureRow : INotifyPropertyChanged
/// </summary>
public string ButtonIcon =>
HasButton && !((StructureFieldComplex)Field).Collapsed
? IconChar.PlusSquare.ToChar()
: IconChar.MinusSquare.ToChar();
? IconChar.MinusSquare.ToChar()
: IconChar.PlusSquare.ToChar();
/// <summary>
/// Глубина отображения поля.
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using AngleSharp.Browser;
using LinqToDB.DataProvider.Access;
using Pf2eDataScrapper.WPF.EntityViewer.Stores;
using Pf2eModel;
@@ -129,13 +128,41 @@ internal class EntityListViewModel : ViewModelBase
#region "Методы кнопок"
public void FirstPage() => Page = 1;
private PageNavigationCommand? _firstPageCommand;
public PageNavigationCommand FirstPageCommand
{
get
{
return _firstPageCommand ??= new PageNavigationCommand(() => { Page = 1; });
}
}
public void PreviousPage() => Page--;
private PageNavigationCommand? _previousPageCommand;
public PageNavigationCommand PreviousPageCommand
{
get
{
return _previousPageCommand ??= new PageNavigationCommand(() => { Page--; });
}
}
public void NextPage() => Page++;
private PageNavigationCommand? _nextPageCommand;
public PageNavigationCommand NextPageCommand
{
get
{
return _nextPageCommand ??= new PageNavigationCommand(() => { Page++; });
}
}
public void LastPage() => Page = PageCount;
private PageNavigationCommand? _lastPageCommand;
public PageNavigationCommand LastPageCommand
{
get
{
return _lastPageCommand ??= new PageNavigationCommand(() => { Page = PageCount; });
}
}
public bool HasPrevious => Page != 1;
@@ -167,3 +194,20 @@ internal class EntityListViewModel : ViewModelBase
#endregion
}
public class PageNavigationCommand(Action action) : System.Windows.Input.ICommand
{
public Action Action { get; } = action;
public event EventHandler? CanExecuteChanged;
public bool CanExecute(object? parameter)
{
return true;
}
public void Execute(object? parameter)
{
Action.Invoke();
}
}