You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
commander/PanelCollectionView.cs

59 lines
2.3 KiB
C#

using Microsoft.Maui.Controls;
namespace CommanderApp;
public static class PanelCollectionView
{
public static DataTemplate CreateItemTemplate(bool isLeftPanel, MainPage page)
{
return new DataTemplate(() =>
{
var button = new Button
{
Padding = new Thickness(15, 8, 5, 8), // left, top, right, bottom
HeightRequest = 40,
BackgroundColor = Colors.Transparent,
BorderWidth = 0,
TextColor = Colors.Black,
HorizontalOptions = LayoutOptions.Fill,
};
button.SetBinding(Button.TextProperty, new Binding("DisplayText"));
button.SetBinding(Button.CommandParameterProperty, new Binding("."));
// Обработчик нажатия
button.Clicked += (s, e) =>
{
if (s is Button btn && btn.CommandParameter is FileSystemItem item)
{
page.HandleItemClick(item, isLeftPanel);
}
};
// Визуальные состояния для фокуса
var visualStateGroups = new VisualStateGroupList();
var commonStates = new VisualStateGroup { Name = "CommonStates" };
var normalState = new VisualState { Name = "Normal" };
normalState.Setters.Add(new Setter { Property = Button.TextColorProperty, Value = Colors.Black });
var focusedState = new VisualState { Name = "Focused" };
focusedState.Setters.Add(new Setter { Property = Button.BorderColorProperty, Value = Colors.Blue });
focusedState.Setters.Add(new Setter { Property = Button.BorderWidthProperty, Value = 2 });
var pressedState = new VisualState { Name = "Pressed" };
pressedState.Setters.Add(new Setter { Property = Button.TextColorProperty, Value = Colors.Black });
pressedState.Setters.Add(new Setter { Property = Button.BackgroundColorProperty, Value = Color.FromArgb("#e0e0e0") });
commonStates.States.Add(normalState);
commonStates.States.Add(focusedState);
//commonStates.States.Add(pressedState);
visualStateGroups.Add(commonStates);
VisualStateManager.SetVisualStateGroups(button, visualStateGroups);
return button;
});
}
}