mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-18 10:10:45 +08:00
refactor:提取 HandlePreviewMouseWheel
This commit is contained in:
25
src/MaaWpfGui/Helper/MouseWheelHelper.cs
Normal file
25
src/MaaWpfGui/Helper/MouseWheelHelper.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace MaaWpfGui.Helper
|
||||
{
|
||||
public static class MouseWheelHelper
|
||||
{
|
||||
public static void HandlePreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
|
||||
{
|
||||
RoutedEvent = UIElement.MouseWheelEvent,
|
||||
};
|
||||
var parent = ((Control)sender).Parent as UIElement;
|
||||
parent?.RaiseEvent(eventArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,42 +4,41 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:helper="clr-namespace:MaaWpfGui.Helper"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:styles="clr-namespace:MaaWpfGui.Styles"
|
||||
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
|
||||
Icon="../../newlogo.ico"
|
||||
Title="{DynamicResource Announcement}"
|
||||
Width="600"
|
||||
Height="500"
|
||||
d:DataContext="{d:DesignInstance {x:Type ui:AnnouncementViewModel}}"
|
||||
Icon="../../newlogo.ico"
|
||||
mc:Ignorable="d">
|
||||
<Grid Background="{DynamicResource VersionUpdateViewBackgroundBrush}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer Background="{DynamicResource VersionUpdateViewBackgroundBrush}">
|
||||
<StackPanel>
|
||||
<mdxam:MarkdownScrollViewer
|
||||
Margin="10,0,10,0"
|
||||
ClickAction="SafetyOpenBrowser"
|
||||
Markdown="{Binding AnnouncementInfo}"
|
||||
PreviewMouseWheel="{s:Action HandlePreviewMouseWheel,
|
||||
Target={x:Type helper:MouseWheelHelper}}">
|
||||
<mdxam:MarkdownScrollViewer.MarkdownStyle>
|
||||
<StaticResource ResourceKey="MdXamlStyle" />
|
||||
</mdxam:MarkdownScrollViewer.MarkdownStyle>
|
||||
<mdxam:MarkdownScrollViewer.Plugins>
|
||||
<StaticResource ResourceKey="MdXamlPlugin" />
|
||||
</mdxam:MarkdownScrollViewer.Plugins>
|
||||
</mdxam:MarkdownScrollViewer>
|
||||
|
||||
<mdxam:MarkdownScrollViewer
|
||||
ClickAction="SafetyOpenBrowser"
|
||||
Grid.Row="0"
|
||||
Markdown="{Binding AnnouncementInfo}"
|
||||
Margin="10,0,10,0">
|
||||
<mdxam:MarkdownScrollViewer.MarkdownStyle>
|
||||
<StaticResource ResourceKey="MdXamlStyle"/>
|
||||
</mdxam:MarkdownScrollViewer.MarkdownStyle>
|
||||
<mdxam:MarkdownScrollViewer.Plugins>
|
||||
<StaticResource ResourceKey="MdXamlPlugin"/>
|
||||
</mdxam:MarkdownScrollViewer.Plugins>
|
||||
</mdxam:MarkdownScrollViewer>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="1"
|
||||
Height="30"
|
||||
Margin="6"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Content="{DynamicResource ShowDisclaimerNoMore}"
|
||||
IsChecked="{Binding DoNotRemindThisAnnouncementAgain}" />
|
||||
</Grid>
|
||||
<CheckBox
|
||||
Height="30"
|
||||
Margin="6"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Content="{DynamicResource ShowDisclaimerNoMore}"
|
||||
IsChecked="{Binding DoNotRemindThisAnnouncementAgain}" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</hc:Window>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:controls="clr-namespace:MaaWpfGui.Styles.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:helper="clr-namespace:MaaWpfGui.Helper"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:ui="clr-namespace:MaaWpfGui.ViewModels.UI"
|
||||
@@ -221,6 +222,8 @@
|
||||
HeadersVisibility="None"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding OperBoxNotHaveList}"
|
||||
PreviewMouseWheel="{s:Action HandlePreviewMouseWheel,
|
||||
Target={x:Type helper:MouseWheelHelper}}"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
Visibility="{c:Binding 'OperBoxNotHaveList.Count != 0'}">
|
||||
@@ -229,11 +232,6 @@
|
||||
<WrapPanel HorizontalAlignment="Center" />
|
||||
</ItemsPanelTemplate>
|
||||
</DataGrid.ItemsPanel>
|
||||
<DataGrid.Resources>
|
||||
<Style BasedOn="{StaticResource {x:Type DataGrid}}" TargetType="{x:Type DataGrid}">
|
||||
<EventSetter Event="PreviewMouseWheel" Handler="DataGrid_PreviewMouseWheel" />
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding}" />
|
||||
</DataGrid.Columns>
|
||||
@@ -255,6 +253,8 @@
|
||||
HeadersVisibility="None"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding OperBoxHaveList}"
|
||||
PreviewMouseWheel="{s:Action HandlePreviewMouseWheel,
|
||||
Target={x:Type helper:MouseWheelHelper}}"
|
||||
ScrollViewer.CanContentScroll="True"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
Visibility="{c:Binding 'OperBoxHaveList.Count != 0'}">
|
||||
@@ -263,11 +263,6 @@
|
||||
<WrapPanel HorizontalAlignment="Center" />
|
||||
</ItemsPanelTemplate>
|
||||
</DataGrid.ItemsPanel>
|
||||
<DataGrid.Resources>
|
||||
<Style BasedOn="{StaticResource {x:Type DataGrid}}" TargetType="{x:Type DataGrid}">
|
||||
<EventSetter Event="PreviewMouseWheel" Handler="DataGrid_PreviewMouseWheel" />
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding}" />
|
||||
</DataGrid.Columns>
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// <copyright file="NotifyIcon.xaml.cs" company="MaaAssistantArknights">
|
||||
// MaaWpfGui - A part of the MaaCoreArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License v3.0 only as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace MaaWpfGui.Views.UI
|
||||
{
|
||||
public partial class RecognizerView
|
||||
{
|
||||
public RecognizerView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void DataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
|
||||
{
|
||||
RoutedEvent = MouseWheelEvent,
|
||||
};
|
||||
var parent = ((Control)sender).Parent as UIElement;
|
||||
parent?.RaiseEvent(eventArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,8 @@
|
||||
dd:DragDrop.IsDragSource="True"
|
||||
dd:DragDrop.IsDropTarget="True"
|
||||
ItemsSource="{Binding Path=InfrastItemViewModels}"
|
||||
PreviewMouseWheel="{s:Action HandlePreviewMouseWheel,
|
||||
Target={x:Type helper:MouseWheelHelper}}"
|
||||
ToolTip="{DynamicResource LabelSequenceTip}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
@@ -118,11 +120,6 @@
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<ListBox.Resources>
|
||||
<Style BasedOn="{StaticResource {x:Type ListBox}}" TargetType="{x:Type ListBox}">
|
||||
<EventSetter Event="PreviewMouseWheel" Handler="ListBox_PreviewMouseWheel" />
|
||||
</Style>
|
||||
</ListBox.Resources>
|
||||
</ListBox>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
@@ -29,21 +29,5 @@ namespace MaaWpfGui.Views.UserControl.TaskQueue
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
if (e.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
|
||||
{
|
||||
RoutedEvent = UIElement.MouseWheelEvent
|
||||
};
|
||||
var parent = ((Control)sender).Parent as UIElement;
|
||||
parent?.RaiseEvent(eventArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user