feat: re-organize file, add IsCloseButtonVisible option.

This commit is contained in:
rabbitism
2024-02-03 20:07:39 +08:00
parent 96ca0d9075
commit 39457f9724
9 changed files with 87 additions and 34 deletions

View File

@@ -16,8 +16,10 @@ public class DialogWindow: Window
public const string PART_TitleArea = "PART_TitleArea";
protected override Type StyleKeyOverride { get; } = typeof(DialogWindow);
private Button? _closeButton;
protected internal Button? _closeButton;
private Panel? _titleArea;
internal bool IsCloseButtonVisible { get; set; }
static DialogWindow()
{
@@ -40,12 +42,16 @@ public class DialogWindow: Window
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
EventHelper.UnregisterClickEvent(OnDefaultClose, _closeButton);
EventHelper.UnregisterClickEvent(OnCloseButtonClicked, _closeButton);
_titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed);
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);
if (_closeButton is not null)
{
_closeButton.IsVisible = IsCloseButtonVisible;
}
_titleArea = e.NameScope.Find<Panel>(PART_TitleArea);
_titleArea?.AddHandler(PointerPressedEvent, OnTitlePointerPressed, RoutingStrategies.Bubble);
EventHelper.RegisterClickEvent(OnDefaultClose, _closeButton);
EventHelper.RegisterClickEvent(OnCloseButtonClicked, _closeButton);
}
private void OnContextRequestClose(object? sender, object? args)
@@ -53,7 +59,7 @@ public class DialogWindow: Window
Close(args);
}
private void OnDefaultClose(object sender, RoutedEventArgs args)
protected internal virtual void OnCloseButtonClicked(object sender, RoutedEventArgs args)
{
if (DataContext is IDialogContext context)
{