Merge pull request #83 from irihitech/issue/82

Fix: fix pointer press handling.
This commit is contained in:
Dong Bin
2024-01-31 20:35:09 +08:00
committed by GitHub
4 changed files with 114 additions and 92 deletions

View File

@@ -15,6 +15,11 @@
<Button Content="Dialog" Command="{Binding DialogCommand}"></Button> <Button Content="Dialog" Command="{Binding DialogCommand}"></Button>
<Button Content="OK" Command="{Binding OKCommand}"></Button> <Button Content="OK" Command="{Binding OKCommand}"></Button>
<Button Content="Cancel" Command="{Binding CancelCommand}"></Button> <Button Content="Cancel" Command="{Binding CancelCommand}"></Button>
<ComboBox>
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
</ComboBox>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@@ -9,5 +9,10 @@
x:Class="Ursa.Demo.Dialogs.PlainDialog"> x:Class="Ursa.Demo.Dialogs.PlainDialog">
<StackPanel> <StackPanel>
<Calendar SelectedDate="{Binding Date}" ></Calendar> <Calendar SelectedDate="{Binding Date}" ></Calendar>
<ComboBox>
<ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem>
</ComboBox>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

View File

@@ -387,13 +387,18 @@
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> <Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" /> <Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" /> <Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<ChromeOverlayLayer /> <VisualLayerManager>
<Grid RowDefinitions="Auto, *"> <Grid RowDefinitions="Auto, *">
<ContentPresenter <ContentPresenter
Grid.Row="0" Grid.Row="0"
Grid.RowSpan="2" Grid.RowSpan="2"
Content="{TemplateBinding Content}" /> Content="{TemplateBinding Content}" />
<Grid Grid.Row="0" ColumnDefinitions="*, Auto"> <Grid Grid.Row="0" ColumnDefinitions="*, Auto">
<Panel
Name="{x:Static u:DialogWindow.PART_TitleArea}"
Grid.Column="0"
Grid.ColumnSpan="2"
Background="Transparent" />
<TextBlock <TextBlock
Grid.Column="0" Grid.Column="0"
Margin="24,24,0,0" Margin="24,24,0,0"
@@ -409,6 +414,7 @@
Theme="{DynamicResource CloseButton}" /> Theme="{DynamicResource CloseButton}" />
</Grid> </Grid>
</Grid> </Grid>
</VisualLayerManager>
</Panel> </Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
@@ -444,7 +450,7 @@
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" /> <Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" /> <Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" /> <Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<ChromeOverlayLayer /> <VisualLayerManager>
<Grid RowDefinitions="Auto, *, Auto"> <Grid RowDefinitions="Auto, *, Auto">
<ContentPresenter <ContentPresenter
Name="PART_ContentPresenter" Name="PART_ContentPresenter"
@@ -453,7 +459,7 @@
Content="{TemplateBinding Content}" /> Content="{TemplateBinding Content}" />
<Grid Grid.Row="0" ColumnDefinitions="Auto, *, Auto"> <Grid Grid.Row="0" ColumnDefinitions="Auto, *, Auto">
<Panel <Panel
Name="{x:Static u:DialogControl.PART_TitleArea}" Name="{x:Static u:DialogWindow.PART_TitleArea}"
Grid.Column="0" Grid.Column="0"
Grid.ColumnSpan="3" Grid.ColumnSpan="3"
Background="Transparent" /> Background="Transparent" />
@@ -513,6 +519,7 @@
Theme="{DynamicResource SolidButton}" /> Theme="{DynamicResource SolidButton}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</VisualLayerManager>
</Panel> </Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

View File

@@ -9,13 +9,15 @@ using Ursa.Common;
namespace Ursa.Controls; namespace Ursa.Controls;
[TemplatePart(PART_CloseButton, typeof(Button))] [TemplatePart(PART_CloseButton, typeof(Button))]
[TemplatePart(PART_TitleArea, typeof(Panel))]
public class DialogWindow: Window public class DialogWindow: Window
{ {
public const string PART_CloseButton = "PART_CloseButton"; public const string PART_CloseButton = "PART_CloseButton";
public const string PART_TitleArea = "PART_TitleArea";
protected override Type StyleKeyOverride { get; } = typeof(DialogWindow); protected override Type StyleKeyOverride { get; } = typeof(DialogWindow);
private Button? _closeButton; private Button? _closeButton;
private Panel? _titleArea;
static DialogWindow() static DialogWindow()
{ {
@@ -39,7 +41,10 @@ public class DialogWindow: Window
{ {
base.OnApplyTemplate(e); base.OnApplyTemplate(e);
EventHelper.UnregisterClickEvent(OnDefaultClose, _closeButton); EventHelper.UnregisterClickEvent(OnDefaultClose, _closeButton);
_titleArea?.RemoveHandler(PointerPressedEvent, OnTitlePointerPressed);
_closeButton = e.NameScope.Find<Button>(PART_CloseButton); _closeButton = e.NameScope.Find<Button>(PART_CloseButton);
_titleArea = e.NameScope.Find<Panel>(PART_TitleArea);
_titleArea?.AddHandler(PointerPressedEvent, OnTitlePointerPressed, RoutingStrategies.Bubble);
EventHelper.RegisterClickEvent(OnDefaultClose, _closeButton); EventHelper.RegisterClickEvent(OnDefaultClose, _closeButton);
} }
@@ -60,7 +65,7 @@ public class DialogWindow: Window
} }
} }
protected override void OnPointerPressed(PointerPressedEventArgs e) private void OnTitlePointerPressed(object sender, PointerPressedEventArgs e)
{ {
this.BeginMoveDrag(e); this.BeginMoveDrag(e);
} }