Merge branch 'master' into pr/84
This commit is contained in:
commit
6d4cbbb7d2
31 files changed
+726
-187
No files matched your search
@@ -38,4 +38,9 @@
|
||||
<ItemGroup>
|
||||
<None Remove="Themes\Styles\Base\TreeViewBaseStyle.xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\dropper.cur">
|
||||
<Link>Resources\dropper.cur</Link>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -100,6 +100,11 @@
|
||||
<LastGenOutput>Lang.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\dropper.cur">
|
||||
<Link>Resources\dropper.cur</Link>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\Shared\HandyControl_Shared\HandyControl_Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -141,6 +141,11 @@
|
||||
<LastGenOutput>Lang.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\dropper.cur">
|
||||
<Link>Resources\dropper.cur</Link>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\Shared\HandyControl_Shared\HandyControl_Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -4,6 +4,9 @@
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<controls:TransitioningContentControl>
|
||||
<controls:Clock Margin="32"/>
|
||||
<StackPanel Orientation="Horizontal" Margin="32">
|
||||
<controls:Clock/>
|
||||
<controls:ListClock Margin="16,0,0,0"/>
|
||||
</StackPanel>
|
||||
</controls:TransitioningContentControl>
|
||||
</UserControl>
|
||||
@@ -17,7 +17,11 @@
|
||||
<controls:TimePicker Width="380" controls:InfoElement.TitleWidth="140" controls:InfoElement.TitleAlignment="Left" controls:InfoElement.Placeholder="{x:Static langs:Lang.PlsEnterContent}" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr3}" Style="{StaticResource TimePickerExtend}" controls:InfoElement.Necessary="True" Margin="0,16,0,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="32,0,0,0">
|
||||
<controls:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerPlus}"/>
|
||||
<controls:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerPlus}">
|
||||
<controls:TimePicker.Clock>
|
||||
<controls:ListClock/>
|
||||
</controls:TimePicker.Clock>
|
||||
</controls:TimePicker>
|
||||
<controls:TimePicker Margin="0,16,0,0" IsEnabled="False" Style="{StaticResource TimePickerPlus}"/>
|
||||
|
||||
<controls:TimePicker ShowClearButton="True" Style="{StaticResource TimePickerPlus}" controls:InfoElement.Title="{x:Static langs:Lang.TitleDemoStr1}" Margin="0,32,0,0"/>
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
<Image Source="../../Resources/Img/LeftMainContent/ToolBar_16x.png"/>
|
||||
</controls:EdgeElement.LeftContent>
|
||||
</ListBoxItem>
|
||||
<ListBoxItem Tag="{x:Static data:MessageToken.BorderDemoCtl}" Content="{x:Static langs:Lang.Border}">
|
||||
<ListBoxItem Tag="{x:Static data:MessageToken.BorderDemoCtl}" Name="ListBoxItemBorder">
|
||||
<controls:EdgeElement.LeftContent>
|
||||
<Image Source="../../Resources/Img/LeftMainContent/BorderElement_16x.png"/>
|
||||
</controls:EdgeElement.LeftContent>
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace HandyControlDemo.UserControl
|
||||
public LeftMainContent()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
/*You have to ask me why I made Border special.
|
||||
What drives me crazy is that if you don't do this,
|
||||
the content of ListBoxItemBorder will always be 1 !
|
||||
How amazing!
|
||||
I wish someone could tell me why. */
|
||||
ListBoxItemBorder.Content = Properties.Langs.Lang.Border;
|
||||
}
|
||||
|
||||
private void TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<ToggleButton Width="128" Margin="0,0,0,10" Content="ToggleButton" Style="{StaticResource ToggleButtonPrimary}"/>
|
||||
<ToggleButton Width="128" Margin="0,0,0,10" Style="{StaticResource ToggleButtonIcon}" controls:IconSwitchElement.Geometry="{StaticResource DeleteGeometry}" controls:IconSwitchElement.GeometrySelected="{StaticResource DownGeometry}"/>
|
||||
<ToggleButton Width="128" Margin="0,0,0,10" IsChecked="True" Content="ToggleButton" controls:IconElement.Geometry="{StaticResource ClockGeometry}" Style="{StaticResource ToggleButtonPrimary}"/>
|
||||
<ToggleButton Margin="0,0,0,10" IsChecked="True" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HiddenElement="True">
|
||||
<ToggleButton Margin="0,0,0,10" IsChecked="True" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HideUncheckedElement="True">
|
||||
<controls:StatusSwitchElement.CheckedElement>
|
||||
<Border Width="128" Height="30" CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}">
|
||||
<Ellipse Width="20" Height="20" Fill="{DynamicResource PrimaryBrush}" StrokeThickness="1" Stroke="{DynamicResource BorderBrush}"/>
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
<TextBlock TextAlignment="Center" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Style="{StaticResource TextBlockDefault}" Text="ToggleButtonIconTransparent"/>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<ToggleButton IsChecked="True" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HiddenElement="True">
|
||||
<ToggleButton IsChecked="True" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HideUncheckedElement="True">
|
||||
<controls:StatusSwitchElement.CheckedElement>
|
||||
<Border Width="80" Height="30" CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Margin="5">
|
||||
<Ellipse Width="20" Height="20" Fill="{DynamicResource PrimaryBrush}" StrokeThickness="1" Stroke="{DynamicResource BorderBrush}"/>
|
||||
@@ -87,7 +87,7 @@
|
||||
<Ellipse Width="20" Height="20" Fill="{DynamicResource BorderBrush}" StrokeThickness="1" Stroke="{DynamicResource BorderBrush}"/>
|
||||
</Border>
|
||||
</ToggleButton>
|
||||
<ToggleButton IsEnabled="False" IsChecked="True" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HiddenElement="True">
|
||||
<ToggleButton IsEnabled="False" IsChecked="True" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HideUncheckedElement="True">
|
||||
<controls:StatusSwitchElement.CheckedElement>
|
||||
<Border Width="80" Height="30" CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Margin="5">
|
||||
<Ellipse Width="20" Height="20" Fill="{DynamicResource PrimaryBrush}" StrokeThickness="1" Stroke="{DynamicResource BorderBrush}"/>
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace HandyControl.Controls
|
||||
/// <summary>
|
||||
/// 是否隐藏元素
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty HiddenElementProperty = DependencyProperty.RegisterAttached(
|
||||
"HiddenElement", typeof(bool), typeof(StatusSwitchElement), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
public static readonly DependencyProperty HideUncheckedElementProperty = DependencyProperty.RegisterAttached(
|
||||
"HideUncheckedElement", typeof(bool), typeof(StatusSwitchElement), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public static void SetHiddenElement(DependencyObject element, bool value) => element.SetValue(HiddenElementProperty, value);
|
||||
public static void SetHideUncheckedElement(DependencyObject element, bool value) => element.SetValue(HideUncheckedElementProperty, value);
|
||||
|
||||
public static bool GetHiddenElement(DependencyObject element) => (bool) element.GetValue(HiddenElementProperty);
|
||||
public static bool GetHideUncheckedElement(DependencyObject element) => (bool) element.GetValue(HideUncheckedElementProperty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
internal class ColorDropper
|
||||
{
|
||||
private bool _cursorIsSetted;
|
||||
|
||||
private Cursor _dropperCursor;
|
||||
|
||||
private readonly ColorPicker _colorPicker;
|
||||
|
||||
public ColorDropper(ColorPicker colorPicker)
|
||||
{
|
||||
_colorPicker = colorPicker;
|
||||
}
|
||||
|
||||
public void Update(bool isShow)
|
||||
{
|
||||
if (isShow)
|
||||
{
|
||||
if (_dropperCursor == null)
|
||||
{
|
||||
var info = Application.GetResourceStream(new Uri("pack://application:,,,/HandyControl;Component/Resources/dropper.cur"));
|
||||
if (info != null)
|
||||
{
|
||||
_dropperCursor = new Cursor(info.Stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (_dropperCursor == null) return;
|
||||
|
||||
MouseHook.Start();
|
||||
MouseHook.StatusChanged += MouseHook_StatusChanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
Mouse.OverrideCursor = Cursors.Arrow;
|
||||
MouseHook.Stop();
|
||||
MouseHook.StatusChanged -= MouseHook_StatusChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void MouseHook_StatusChanged(object sender, MouseHookEventArgs e)
|
||||
{
|
||||
var window = System.Windows.Window.GetWindow(_colorPicker);
|
||||
if (window == null)
|
||||
{
|
||||
UpdateCursor(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_colorPicker.IsMouseOver && window.IsMouseOver)
|
||||
{
|
||||
UpdateCursor(true);
|
||||
if (e.Message == MouseHookMessageType.LeftButtonDown)
|
||||
{
|
||||
var brush = new SolidColorBrush(GetColorAt(e.Point.X, e.Point.Y));
|
||||
_colorPicker.SelectedBrush = brush;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCursor(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCursor(bool isDropper)
|
||||
{
|
||||
if (isDropper)
|
||||
{
|
||||
Mouse.Captured?.ReleaseMouseCapture();
|
||||
|
||||
if (!_cursorIsSetted)
|
||||
{
|
||||
Mouse.OverrideCursor = _dropperCursor;
|
||||
_cursorIsSetted = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_cursorIsSetted)
|
||||
{
|
||||
Mouse.OverrideCursor = Cursors.Arrow;
|
||||
_cursorIsSetted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Color GetColorAt(int x, int y)
|
||||
{
|
||||
var desk = UnsafeNativeMethods.GetDesktopWindow();
|
||||
var dc = UnsafeNativeMethods.GetWindowDC(desk);
|
||||
var a = (int)UnsafeNativeMethods.GetPixel(dc, x, y);
|
||||
UnsafeNativeMethods.ReleaseDC(desk, dc);
|
||||
return Color.FromArgb(255, (byte) ((a >> 0) & 0xff), (byte) ((a >> 8) & 0xff), (byte) ((a >> 16) & 0xff));
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
-2
@@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Interactivity;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
@@ -21,6 +23,7 @@ namespace HandyControl.Controls
|
||||
[TemplatePart(Name = ElementSliderColor, Type = typeof(Panel))]
|
||||
[TemplatePart(Name = ElementSliderOpacity, Type = typeof(Panel))]
|
||||
[TemplatePart(Name = ElementPanelRgb, Type = typeof(Panel))]
|
||||
[TemplatePart(Name = ElementButtonDropper, Type = typeof(ToggleButton))]
|
||||
public class ColorPicker : Control, ISingleOpen
|
||||
{
|
||||
#region Constants
|
||||
@@ -32,11 +35,16 @@ namespace HandyControl.Controls
|
||||
private const string ElementSliderColor = "PART_SliderColor";
|
||||
private const string ElementSliderOpacity = "PART_SliderOpacity";
|
||||
private const string ElementPanelRgb = "PART_PanelRgb";
|
||||
private const string ElementButtonDropper = "PART_ButtonDropper";
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Data
|
||||
|
||||
private ColorDropper _colorDropper;
|
||||
|
||||
private ToggleButton _toggleButtonDropper;
|
||||
|
||||
private Panel _panelRgb;
|
||||
|
||||
private Border _borderColor;
|
||||
@@ -53,6 +61,8 @@ namespace HandyControl.Controls
|
||||
|
||||
private bool _appliedTemplate;
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// 当前显示的颜色类型
|
||||
/// </summary>
|
||||
@@ -332,6 +342,11 @@ namespace HandyControl.Controls
|
||||
}
|
||||
}
|
||||
|
||||
~ColorPicker()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public ColorPicker()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Confirm, ButtonConfirm_OnClick));
|
||||
@@ -361,6 +376,11 @@ namespace HandyControl.Controls
|
||||
_sliderOpacity.ValueChanged -= SliderOpacity_OnValueChanged;
|
||||
}
|
||||
|
||||
if (_toggleButtonDropper != null)
|
||||
{
|
||||
_toggleButtonDropper.Click -= ToggleButtonDropper_Click;
|
||||
}
|
||||
|
||||
_panelColor?.Children.Clear();
|
||||
|
||||
_panelRgb?.RemoveHandler(NumericUpDown.ValueChangedEvent, new EventHandler<FunctionEventArgs<double>>(NumericUpDownRgb_OnValueChanged));
|
||||
@@ -374,6 +394,7 @@ namespace HandyControl.Controls
|
||||
_sliderColor = GetTemplateChild(ElementSliderColor) as Slider;
|
||||
_sliderOpacity = GetTemplateChild(ElementSliderOpacity) as Slider;
|
||||
_panelRgb = GetTemplateChild(ElementPanelRgb) as Panel;
|
||||
_toggleButtonDropper = GetTemplateChild(ElementButtonDropper) as ToggleButton;
|
||||
|
||||
if (_sliderColor != null)
|
||||
{
|
||||
@@ -395,6 +416,11 @@ namespace HandyControl.Controls
|
||||
collection.Add(behavior);
|
||||
}
|
||||
|
||||
if (_toggleButtonDropper != null)
|
||||
{
|
||||
_toggleButtonDropper.Click += ToggleButtonDropper_Click;
|
||||
}
|
||||
|
||||
_appliedTemplate = true;
|
||||
if (_isLoaded)
|
||||
{
|
||||
@@ -428,7 +454,7 @@ namespace HandyControl.Controls
|
||||
var button = new Button
|
||||
{
|
||||
Margin = new Thickness(0, 0, 12, 12),
|
||||
Style = FindResource("ButtonCustom") as Style,
|
||||
Style = ResourceHelper.GetResource<Style>(ResourceToken.ButtonCustom),
|
||||
Content = new Border
|
||||
{
|
||||
Background = brush,
|
||||
@@ -675,8 +701,35 @@ namespace HandyControl.Controls
|
||||
|
||||
private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) => RaiseEvent(new RoutedEventArgs(CanceledEvent));
|
||||
|
||||
public void Dispose() => System.Windows.Window.GetWindow(this)?.Close();
|
||||
private void ToggleButtonDropper_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_colorDropper == null)
|
||||
{
|
||||
_colorDropper = new ColorDropper(this);
|
||||
}
|
||||
// ReSharper disable once PossibleInvalidOperationException
|
||||
_colorDropper.Update(_toggleButtonDropper.IsChecked.Value);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed) return;
|
||||
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
_colorDropper?.Update(false);
|
||||
System.Windows.Window.GetWindow(this)?.Close();
|
||||
}));
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public bool CanDispose { get; } = true;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -99,15 +99,6 @@ namespace HandyControl.Controls
|
||||
set => SetValue(DateTimeFormatProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ClockStyleProperty = DependencyProperty.Register(
|
||||
"ClockStyle", typeof(Style), typeof(DateTimePicker), new PropertyMetadata(default(Style)));
|
||||
|
||||
public Style ClockStyle
|
||||
{
|
||||
get => (Style) GetValue(ClockStyleProperty);
|
||||
set => SetValue(ClockStyleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CalendarStyleProperty = DependencyProperty.Register(
|
||||
"CalendarStyle", typeof(Style), typeof(DateTimePicker), new PropertyMetadata(default(Style)));
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ namespace HandyControl.Controls
|
||||
|
||||
#region Data
|
||||
|
||||
private Clock _clock;
|
||||
|
||||
private string _defaultText;
|
||||
|
||||
private ButtonBase _dropDownButton;
|
||||
@@ -79,7 +77,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public TimePicker()
|
||||
{
|
||||
InitClock();
|
||||
Clock = new Clock();
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
|
||||
{
|
||||
ClearValue(SelectedTimeProperty);
|
||||
@@ -103,18 +101,6 @@ namespace HandyControl.Controls
|
||||
|
||||
#endregion TimeFormat
|
||||
|
||||
#region ClockStyle
|
||||
|
||||
public Style ClockStyle
|
||||
{
|
||||
get => (Style)GetValue(ClockStyleProperty);
|
||||
set => SetValue(ClockStyleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ClockStyleProperty = DependencyProperty.Register("ClockStyle", typeof(Style), typeof(TimePicker));
|
||||
|
||||
#endregion CalendarStyle
|
||||
|
||||
#region DisplayTime
|
||||
|
||||
public DateTime DisplayTime
|
||||
@@ -133,8 +119,8 @@ namespace HandyControl.Controls
|
||||
private static object CoerceDisplayTime(DependencyObject d, object value)
|
||||
{
|
||||
var dp = (TimePicker)d;
|
||||
dp._clock.DisplayTime = (DateTime)value;
|
||||
return dp._clock.DisplayTime;
|
||||
dp.Clock.DisplayTime = (DateTime)value;
|
||||
return dp.Clock.DisplayTime;
|
||||
}
|
||||
|
||||
#endregion DisplayTime
|
||||
@@ -170,7 +156,7 @@ namespace HandyControl.Controls
|
||||
|
||||
dp.Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action)delegate
|
||||
{
|
||||
dp._clock.Focus();
|
||||
dp.Clock.Focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -212,8 +198,8 @@ namespace HandyControl.Controls
|
||||
private static object CoerceSelectedTime(DependencyObject d, object value)
|
||||
{
|
||||
var dp = (TimePicker)d;
|
||||
dp._clock.SelectedTime = (DateTime?)value;
|
||||
return dp._clock.SelectedTime;
|
||||
dp.Clock.SelectedTime = (DateTime?)value;
|
||||
return dp.Clock.SelectedTime;
|
||||
}
|
||||
|
||||
#endregion SelectedDate
|
||||
@@ -306,6 +292,35 @@ namespace HandyControl.Controls
|
||||
set => SetValue(ShowClearButtonProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ClockProperty = DependencyProperty.Register(
|
||||
"Clock", typeof(ClockBase), typeof(TimePicker), new FrameworkPropertyMetadata(default(Clock), FrameworkPropertyMetadataOptions.NotDataBindable, OnClockChanged));
|
||||
|
||||
private static void OnClockChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (TimePicker) d;
|
||||
var oldClock = e.OldValue as ClockBase;
|
||||
var newClock = e.NewValue as ClockBase;
|
||||
|
||||
if (oldClock != null)
|
||||
{
|
||||
oldClock.SelectedTimeChanged -= ctl.Clock_SelectedTimeChanged;
|
||||
oldClock.Confirmed -= ctl.Clock_Confirmed;
|
||||
}
|
||||
|
||||
if (newClock != null)
|
||||
{
|
||||
newClock.ShowConfirmButton = true;
|
||||
newClock.SelectedTimeChanged += ctl.Clock_SelectedTimeChanged;
|
||||
newClock.Confirmed += ctl.Clock_Confirmed;
|
||||
}
|
||||
}
|
||||
|
||||
public ClockBase Clock
|
||||
{
|
||||
get => (ClockBase) GetValue(ClockProperty);
|
||||
set => SetValue(ClockProperty, value);
|
||||
}
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
@@ -374,7 +389,7 @@ namespace HandyControl.Controls
|
||||
_popUp.PreviewMouseLeftButtonDown += PopUp_PreviewMouseLeftButtonDown;
|
||||
_popUp.Opened += PopUp_Opened;
|
||||
_popUp.Closed += PopUp_Closed;
|
||||
_popUp.Child = _clock;
|
||||
_popUp.Child = Clock;
|
||||
|
||||
if (IsDropDownOpen)
|
||||
{
|
||||
@@ -439,20 +454,7 @@ namespace HandyControl.Controls
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private void InitClock()
|
||||
{
|
||||
_clock = new Clock
|
||||
{
|
||||
ShowConfirmButton = true
|
||||
};
|
||||
_clock.SelectedTimeChanged += Clock_SelectedTimeChanged;
|
||||
_clock.Confirmed += Clock_Confirmed;
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SetSelectedTime();
|
||||
}
|
||||
private void TextBox_LostFocus(object sender, RoutedEventArgs e) => SetSelectedTime();
|
||||
|
||||
private void SetIsHandlerSuspended(DependencyProperty property, bool value)
|
||||
{
|
||||
@@ -560,7 +562,7 @@ namespace HandyControl.Controls
|
||||
SetCurrentValue(IsDropDownOpenProperty, ValueBoxes.TrueBox);
|
||||
}
|
||||
|
||||
_clock?.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
Clock?.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
|
||||
OnClockOpened(new RoutedEventArgs());
|
||||
}
|
||||
@@ -572,7 +574,7 @@ namespace HandyControl.Controls
|
||||
SetCurrentValue(IsDropDownOpenProperty, ValueBoxes.FalseBox);
|
||||
}
|
||||
|
||||
if (_clock.IsKeyboardFocusWithin)
|
||||
if (Clock.IsKeyboardFocusWithin)
|
||||
{
|
||||
MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace HandyControl.Controls
|
||||
/// <summary>
|
||||
/// 当前垂直滚动偏移
|
||||
/// </summary>
|
||||
private static readonly DependencyProperty CurrentVerticalOffsetProperty = DependencyProperty.Register(
|
||||
internal static readonly DependencyProperty CurrentVerticalOffsetProperty = DependencyProperty.Register(
|
||||
"CurrentVerticalOffset", typeof(double), typeof(ScrollViewer), new PropertyMetadata(ValueBoxes.Double0Box, OnCurrentVerticalOffsetChanged));
|
||||
|
||||
private static void OnCurrentVerticalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
@@ -206,7 +206,7 @@ namespace HandyControl.Controls
|
||||
/// <summary>
|
||||
/// 当前垂直滚动偏移
|
||||
/// </summary>
|
||||
private double CurrentVerticalOffset
|
||||
internal double CurrentVerticalOffset
|
||||
{
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
get => (double) GetValue(CurrentVerticalOffsetProperty);
|
||||
@@ -216,7 +216,7 @@ namespace HandyControl.Controls
|
||||
/// <summary>
|
||||
/// 当前水平滚动偏移
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty CurrentHorizontalOffsetProperty = DependencyProperty.Register(
|
||||
internal static readonly DependencyProperty CurrentHorizontalOffsetProperty = DependencyProperty.Register(
|
||||
"CurrentHorizontalOffset", typeof(double), typeof(ScrollViewer), new PropertyMetadata(ValueBoxes.Double0Box, OnCurrentHorizontalOffsetChanged));
|
||||
|
||||
private static void OnCurrentHorizontalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
@@ -230,7 +230,7 @@ namespace HandyControl.Controls
|
||||
/// <summary>
|
||||
/// 当前水平滚动偏移
|
||||
/// </summary>
|
||||
public double CurrentHorizontalOffset
|
||||
internal double CurrentHorizontalOffset
|
||||
{
|
||||
get => (double) GetValue(CurrentHorizontalOffsetProperty);
|
||||
set => SetValue(CurrentHorizontalOffsetProperty, value);
|
||||
|
||||
@@ -6,26 +6,23 @@ using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementButtonAm, Type = typeof(RadioButton))]
|
||||
[TemplatePart(Name = ElementButtonPm, Type = typeof(RadioButton))]
|
||||
[TemplatePart(Name = ElementButtonConfirm, Type = typeof(Button))]
|
||||
[TemplatePart(Name = ElementCanvas, Type = typeof(Canvas))]
|
||||
[TemplatePart(Name = ElementBorderTitle, Type = typeof(Border))]
|
||||
[TemplatePart(Name = ElementBorderClock, Type = typeof(Border))]
|
||||
[TemplatePart(Name = ElementPanelNum, Type = typeof(CirclePanel))]
|
||||
[TemplatePart(Name = ElementTimeStr, Type = typeof(TextBlock))]
|
||||
public class Clock : Control
|
||||
public class Clock : ClockBase
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string ElementButtonAm = "PART_ButtonAm";
|
||||
private const string ElementButtonPm = "PART_ButtonPm";
|
||||
private const string ElementButtonConfirm = "PART_ButtonConfirm";
|
||||
private const string ElementCanvas = "PART_Canvas";
|
||||
private const string ElementBorderTitle = "PART_BorderTitle";
|
||||
private const string ElementBorderClock = "PART_BorderClock";
|
||||
@@ -40,8 +37,6 @@ namespace HandyControl.Controls
|
||||
|
||||
private RadioButton _buttonPm;
|
||||
|
||||
private Button _buttonConfirm;
|
||||
|
||||
private Canvas _canvas;
|
||||
|
||||
private Border _borderTitle;
|
||||
@@ -60,59 +55,10 @@ namespace HandyControl.Controls
|
||||
|
||||
private int _secValue;
|
||||
|
||||
private bool _appliedTemplate;
|
||||
|
||||
#endregion Data
|
||||
|
||||
#region Public Events
|
||||
|
||||
public static readonly RoutedEvent SelectedTimeChangedEvent =
|
||||
EventManager.RegisterRoutedEvent("SelectedTimeChanged", RoutingStrategy.Direct,
|
||||
typeof(EventHandler<FunctionEventArgs<DateTime?>>), typeof(Clock));
|
||||
|
||||
public event EventHandler<FunctionEventArgs<DateTime?>> SelectedTimeChanged
|
||||
{
|
||||
add => AddHandler(SelectedTimeChangedEvent, value);
|
||||
remove => RemoveHandler(SelectedTimeChangedEvent, value);
|
||||
}
|
||||
|
||||
public event EventHandler<FunctionEventArgs<DateTime>> DisplayTimeChanged;
|
||||
|
||||
public event Action Confirmed;
|
||||
|
||||
#endregion Public Events
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public static readonly DependencyProperty SelectedTimeProperty = DependencyProperty.Register(
|
||||
"SelectedTime", typeof(DateTime?), typeof(Clock), new PropertyMetadata(default(DateTime?), OnSelectedTimeChanged));
|
||||
|
||||
private static void OnSelectedTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Clock)d;
|
||||
var v = (DateTime?)e.NewValue;
|
||||
ctl.DisplayTime = v ?? DateTime.Now;
|
||||
ctl.OnSelectedTimeChanged(new FunctionEventArgs<DateTime?>(SelectedTimeChangedEvent, ctl)
|
||||
{
|
||||
Info = v
|
||||
});
|
||||
}
|
||||
|
||||
public DateTime? SelectedTime
|
||||
{
|
||||
get => (DateTime?) GetValue(SelectedTimeProperty);
|
||||
set => SetValue(SelectedTimeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TimeFormatProperty = DependencyProperty.Register(
|
||||
"TimeFormat", typeof(string), typeof(Clock), new PropertyMetadata("HH:mm:ss"));
|
||||
|
||||
public string TimeFormat
|
||||
{
|
||||
get => (string) GetValue(TimeFormatProperty);
|
||||
set => SetValue(TimeFormatProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ClockRadioButtonStyleProperty = DependencyProperty.Register(
|
||||
"ClockRadioButtonStyle", typeof(Style), typeof(Clock), new PropertyMetadata(default(Style)));
|
||||
|
||||
@@ -122,32 +68,6 @@ namespace HandyControl.Controls
|
||||
set => SetValue(ClockRadioButtonStyleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty DisplayTimeProperty = DependencyProperty.Register(
|
||||
"DisplayTime", typeof(DateTime), typeof(Clock), new FrameworkPropertyMetadata(DateTime.Now, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnDisplayTimeChanged));
|
||||
|
||||
private static void OnDisplayTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Clock) d;
|
||||
var v = (DateTime) e.NewValue;
|
||||
ctl.Update(v);
|
||||
ctl.OnDisplayTimeChanged(new FunctionEventArgs<DateTime>(v));
|
||||
}
|
||||
|
||||
public DateTime DisplayTime
|
||||
{
|
||||
get => (DateTime) GetValue(DisplayTimeProperty);
|
||||
set => SetValue(DisplayTimeProperty, value);
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty ShowConfirmButtonProperty = DependencyProperty.Register(
|
||||
"ShowConfirmButton", typeof(bool), typeof(Clock), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
internal bool ShowConfirmButton
|
||||
{
|
||||
get => (bool)GetValue(ShowConfirmButtonProperty);
|
||||
set => SetValue(ShowConfirmButtonProperty, value);
|
||||
}
|
||||
|
||||
private int SecValue
|
||||
{
|
||||
get => _secValue;
|
||||
@@ -174,7 +94,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
_appliedTemplate = false;
|
||||
AppliedTemplate = false;
|
||||
if (_buttonAm != null)
|
||||
{
|
||||
_buttonAm.Click -= ButtonAm_OnClick;
|
||||
@@ -185,9 +105,9 @@ namespace HandyControl.Controls
|
||||
_buttonPm.Click -= ButtonPm_OnClick;
|
||||
}
|
||||
|
||||
if (_buttonConfirm != null)
|
||||
if (ButtonConfirm != null)
|
||||
{
|
||||
_buttonConfirm.Click -= ButtonConfirm_OnClick;
|
||||
ButtonConfirm.Click -= ButtonConfirm_OnClick;
|
||||
}
|
||||
|
||||
if (_borderTitle != null)
|
||||
@@ -206,18 +126,18 @@ namespace HandyControl.Controls
|
||||
|
||||
_buttonAm = GetTemplateChild(ElementButtonAm) as RadioButton;
|
||||
_buttonPm = GetTemplateChild(ElementButtonPm) as RadioButton;
|
||||
_buttonConfirm = GetTemplateChild(ElementButtonConfirm) as Button;
|
||||
ButtonConfirm = GetTemplateChild(ElementButtonConfirm) as Button;
|
||||
_borderTitle = GetTemplateChild(ElementBorderTitle) as Border;
|
||||
_canvas = GetTemplateChild(ElementCanvas) as Canvas;
|
||||
_borderClock = GetTemplateChild(ElementBorderClock) as Border;
|
||||
_circlePanel = GetTemplateChild(ElementPanelNum) as CirclePanel;
|
||||
_blockTime = GetTemplateChild(ElementTimeStr) as TextBlock;
|
||||
|
||||
CheckNull();
|
||||
if (!CheckNull()) return;
|
||||
|
||||
_buttonAm.Click += ButtonAm_OnClick;
|
||||
_buttonPm.Click += ButtonPm_OnClick;
|
||||
_buttonConfirm.Click += ButtonConfirm_OnClick;
|
||||
ButtonConfirm.Click += ButtonConfirm_OnClick;
|
||||
_borderTitle.MouseWheel += BorderTitle_OnMouseWheel;
|
||||
|
||||
_canvas.MouseWheel += Canvas_OnMouseWheel;
|
||||
@@ -241,7 +161,7 @@ namespace HandyControl.Controls
|
||||
_circlePanel.Children.Add(button);
|
||||
}
|
||||
|
||||
_appliedTemplate = true;
|
||||
AppliedTemplate = true;
|
||||
if (SelectedTime.HasValue)
|
||||
{
|
||||
Update(SelectedTime.Value);
|
||||
@@ -255,26 +175,15 @@ namespace HandyControl.Controls
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
|
||||
protected virtual void OnSelectedTimeChanged(FunctionEventArgs<DateTime?> e) => RaiseEvent(e);
|
||||
|
||||
protected virtual void OnDisplayTimeChanged(FunctionEventArgs<DateTime> e)
|
||||
{
|
||||
var handler = DisplayTimeChanged;
|
||||
handler?.Invoke(this, e);
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void CheckNull()
|
||||
private bool CheckNull()
|
||||
{
|
||||
|
||||
if (_buttonPm == null || _buttonAm == null || _buttonConfirm == null || _canvas == null ||
|
||||
if (_buttonPm == null || _buttonAm == null || ButtonConfirm == null || _canvas == null ||
|
||||
_borderTitle == null || _borderClock == null || _circlePanel == null ||
|
||||
_blockTime == null) throw new Exception();
|
||||
_blockTime == null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void BorderTitle_OnMouseWheel(object sender, MouseWheelEventArgs e)
|
||||
@@ -339,7 +248,7 @@ namespace HandyControl.Controls
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_appliedTemplate) return;
|
||||
if (!AppliedTemplate) return;
|
||||
var hValue = _currentButton.Num;
|
||||
if (_buttonPm.IsChecked == true)
|
||||
{
|
||||
@@ -367,9 +276,9 @@ namespace HandyControl.Controls
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
internal void Update(DateTime time)
|
||||
internal override void Update(DateTime time)
|
||||
{
|
||||
if (!_appliedTemplate) return;
|
||||
if (!AppliedTemplate) return;
|
||||
var h = time.Hour;
|
||||
var m = time.Minute;
|
||||
|
||||
@@ -396,12 +305,6 @@ namespace HandyControl.Controls
|
||||
Update();
|
||||
}
|
||||
|
||||
private void ButtonConfirm_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedTime = DisplayTime;
|
||||
Confirmed?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取显示时间
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementButtonConfirm, Type = typeof(Button))]
|
||||
public abstract class ClockBase : Control
|
||||
{
|
||||
protected const string ElementButtonConfirm = "PART_ButtonConfirm";
|
||||
|
||||
protected Button ButtonConfirm;
|
||||
|
||||
protected bool AppliedTemplate;
|
||||
|
||||
public event Action Confirmed;
|
||||
|
||||
public event EventHandler<FunctionEventArgs<DateTime>> DisplayTimeChanged;
|
||||
|
||||
public static readonly RoutedEvent SelectedTimeChangedEvent =
|
||||
EventManager.RegisterRoutedEvent("SelectedTimeChanged", RoutingStrategy.Direct,
|
||||
typeof(EventHandler<FunctionEventArgs<DateTime?>>), typeof(ClockBase));
|
||||
|
||||
public event EventHandler<FunctionEventArgs<DateTime?>> SelectedTimeChanged
|
||||
{
|
||||
add => AddHandler(SelectedTimeChangedEvent, value);
|
||||
remove => RemoveHandler(SelectedTimeChangedEvent, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TimeFormatProperty = DependencyProperty.Register(
|
||||
"TimeFormat", typeof(string), typeof(ClockBase), new PropertyMetadata("HH:mm:ss"));
|
||||
|
||||
public string TimeFormat
|
||||
{
|
||||
get => (string)GetValue(TimeFormatProperty);
|
||||
set => SetValue(TimeFormatProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelectedTimeProperty = DependencyProperty.Register(
|
||||
"SelectedTime", typeof(DateTime?), typeof(ClockBase), new PropertyMetadata(default(DateTime?), OnSelectedTimeChanged));
|
||||
|
||||
private static void OnSelectedTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (ClockBase)d;
|
||||
var v = (DateTime?)e.NewValue;
|
||||
ctl.DisplayTime = v ?? DateTime.Now;
|
||||
ctl.OnSelectedTimeChanged(new FunctionEventArgs<DateTime?>(SelectedTimeChangedEvent, ctl)
|
||||
{
|
||||
Info = v
|
||||
});
|
||||
}
|
||||
|
||||
public DateTime? SelectedTime
|
||||
{
|
||||
get => (DateTime?) GetValue(SelectedTimeProperty);
|
||||
set => SetValue(SelectedTimeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty DisplayTimeProperty = DependencyProperty.Register(
|
||||
"DisplayTime", typeof(DateTime), typeof(ClockBase),
|
||||
new FrameworkPropertyMetadata(DateTime.Now, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
OnDisplayTimeChanged));
|
||||
|
||||
private static void OnDisplayTimeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (ClockBase)d;
|
||||
var v = (DateTime)e.NewValue;
|
||||
ctl.Update(v);
|
||||
ctl.OnDisplayTimeChanged(new FunctionEventArgs<DateTime>(v));
|
||||
}
|
||||
|
||||
public DateTime DisplayTime
|
||||
{
|
||||
get => (DateTime)GetValue(DisplayTimeProperty);
|
||||
set => SetValue(DisplayTimeProperty, value);
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty ShowConfirmButtonProperty = DependencyProperty.Register(
|
||||
"ShowConfirmButton", typeof(bool), typeof(ClockBase), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
internal bool ShowConfirmButton
|
||||
{
|
||||
get => (bool) GetValue(ShowConfirmButtonProperty);
|
||||
set => SetValue(ShowConfirmButtonProperty, value);
|
||||
}
|
||||
|
||||
protected virtual void OnSelectedTimeChanged(FunctionEventArgs<DateTime?> e) => RaiseEvent(e);
|
||||
|
||||
protected virtual void OnDisplayTimeChanged(FunctionEventArgs<DateTime> e)
|
||||
{
|
||||
var handler = DisplayTimeChanged;
|
||||
handler?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected void ButtonConfirm_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectedTime = DisplayTime;
|
||||
Confirmed?.Invoke();
|
||||
}
|
||||
|
||||
internal abstract void Update(DateTime time);
|
||||
|
||||
protected void Clock_SelectedTimeChanged(object sender, FunctionEventArgs<DateTime?> e) => SelectedTime = e.Info;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementHourList, Type = typeof(ListBox))]
|
||||
[TemplatePart(Name = ElementMinuteList, Type = typeof(ListBox))]
|
||||
[TemplatePart(Name = ElementSecondList, Type = typeof(ListBox))]
|
||||
public class ListClock : ClockBase
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string ElementHourList = "PART_HourList";
|
||||
private const string ElementMinuteList = "PART_MinuteList";
|
||||
private const string ElementSecondList = "PART_SecondList";
|
||||
|
||||
#endregion Constants
|
||||
|
||||
#region Data
|
||||
|
||||
private ListBox _hourList;
|
||||
|
||||
private ListBox _minuteList;
|
||||
|
||||
private ListBox _secondList;
|
||||
|
||||
#endregion Data
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
AppliedTemplate = false;
|
||||
if (ButtonConfirm != null)
|
||||
{
|
||||
ButtonConfirm.Click -= ButtonConfirm_OnClick;
|
||||
}
|
||||
|
||||
if (_hourList != null)
|
||||
{
|
||||
_hourList.SelectionChanged -= HourList_SelectionChanged;
|
||||
}
|
||||
|
||||
if (_minuteList != null)
|
||||
{
|
||||
_minuteList.SelectionChanged -= MinuteList_SelectionChanged;
|
||||
}
|
||||
|
||||
if (_secondList != null)
|
||||
{
|
||||
_secondList.SelectionChanged -= SecondList_SelectionChanged;
|
||||
}
|
||||
|
||||
base.OnApplyTemplate();
|
||||
|
||||
_hourList = GetTemplateChild(ElementHourList) as ListBox;
|
||||
if (_hourList != null)
|
||||
{
|
||||
CreateItemsSource(_hourList, 24);
|
||||
_hourList.SelectionChanged += HourList_SelectionChanged;
|
||||
}
|
||||
|
||||
_minuteList = GetTemplateChild(ElementMinuteList) as ListBox;
|
||||
if (_minuteList != null)
|
||||
{
|
||||
CreateItemsSource(_minuteList, 60);
|
||||
_minuteList.SelectionChanged += MinuteList_SelectionChanged;
|
||||
}
|
||||
|
||||
_secondList = GetTemplateChild(ElementSecondList) as ListBox;
|
||||
if (_secondList != null)
|
||||
{
|
||||
CreateItemsSource(_secondList, 60);
|
||||
_secondList.SelectionChanged += SecondList_SelectionChanged;
|
||||
}
|
||||
|
||||
ButtonConfirm = GetTemplateChild(ElementButtonConfirm) as Button;
|
||||
|
||||
if (ButtonConfirm != null)
|
||||
{
|
||||
ButtonConfirm.Click += ButtonConfirm_OnClick;
|
||||
}
|
||||
|
||||
AppliedTemplate = true;
|
||||
if (SelectedTime.HasValue)
|
||||
{
|
||||
Update(SelectedTime.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayTime = DateTime.Now;
|
||||
Update(DisplayTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void HourList_SelectionChanged(object sender, SelectionChangedEventArgs e) => Update();
|
||||
|
||||
private void MinuteList_SelectionChanged(object sender, SelectionChangedEventArgs e) => Update();
|
||||
|
||||
private void SecondList_SelectionChanged(object sender, SelectionChangedEventArgs e) => Update();
|
||||
|
||||
private void CreateItemsSource(ItemsControl selector, int count)
|
||||
{
|
||||
var list = new List<string>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
list.Add(i.ToString("#00"));
|
||||
}
|
||||
|
||||
selector.ItemsSource = list;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_hourList.SelectedIndex >= 0 && _hourList.SelectedIndex < 24 &&
|
||||
_minuteList.SelectedIndex >= 0 && _minuteList.SelectedIndex < 60 &&
|
||||
_secondList.SelectedIndex >= 0 && _secondList.SelectedIndex < 60)
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
DisplayTime = new DateTime(now.Year, now.Month, now.Day, _hourList.SelectedIndex,
|
||||
_minuteList.SelectedIndex, _secondList.SelectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
internal override void Update(DateTime time)
|
||||
{
|
||||
if (!AppliedTemplate) return;
|
||||
|
||||
var h = time.Hour;
|
||||
var m = time.Minute;
|
||||
var s = time.Second;
|
||||
|
||||
_hourList.SelectedIndex = h;
|
||||
_minuteList.SelectedIndex = m;
|
||||
_secondList.SelectedIndex = s;
|
||||
|
||||
_hourList.ScrollIntoView(_hourList.SelectedItem);
|
||||
_minuteList.ScrollIntoView(_minuteList.SelectedItem);
|
||||
_secondList.ScrollIntoView(_secondList.SelectedItem);
|
||||
|
||||
DisplayTime = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal class MouseHookEventArgs : EventArgs
|
||||
{
|
||||
public MouseHookMessageType Message { get; set; }
|
||||
|
||||
public NativeMethods.POINT Point { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public enum MouseHookMessageType
|
||||
{
|
||||
LeftButtonDown = 0x0201,
|
||||
LeftButtonUp = 0x0202,
|
||||
MouseMove = 0x0200,
|
||||
MouseWheel = 0x020A,
|
||||
RightButtonDown = 0x0204,
|
||||
RightButtonUp = 0x0205
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using HandyControl.Controls;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\ContextMenuButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\ContextMenuToggleButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\ProgressButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\ColorPicker\ColorDropper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Cover\CoverFlow\CoverFlow.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Cover\CoverFlow\CoverFlowItem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Cover\CoverView\CoverView.cs" />
|
||||
@@ -62,7 +63,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Badge.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Carousel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ChatBubble.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ColorPicker.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\ColorPicker\ColorPicker.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Dialog.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\GotoTop.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Gravatar.cs" />
|
||||
@@ -97,7 +98,9 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Text\Tag\TagPanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\CalendarWithClock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\Clock\Clock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\Clock\ListClock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\Clock\ClockRadioButton.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\Clock\ClockBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\FlipClock\FlipClock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\FlipClock\FlipNumber.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Time\TimeBar\SpeTextBlock.cs" />
|
||||
@@ -112,6 +115,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Window\Window.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\CancelRoutedEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\FunctionEventArgs!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Args\MouseHookEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\ColorRange.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\BadgeStatus.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ChatMessageType.cs" />
|
||||
@@ -135,6 +139,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\GrowlInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\HandyControlConfig.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\MessageBoxInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\MouseHookMessageType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Operation\OperationResult!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Operation\OperationResult.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\ResourceToken.cs" />
|
||||
@@ -243,6 +248,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SingleOpenHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ValidateHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\VisualHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Hook\MouseHook.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\BitmapHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\BITMAPINFO.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\CommonHandles.cs" />
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
@@ -38,5 +38,6 @@
|
||||
<Geometry x:Key="AskGeometry">M512 0 30.11843 240.941297l0 542.117406 481.88157 240.941297 481.88157-240.941297L993.88157 240.941297 512 0zM575.776472 768.799969 460.188012 768.799969 460.188012 656.222073l115.588459 0L575.776472 768.799969zM623.335603 509.329685c-52.375829 36.723353-59.600363 55.988096-59.600363 84.885211l0 19.866447L468.616977 614.081343l0-26.489278c0-45.754021 13.846342-80.67124 61.406497-116.791866 46.957428-36.723353 57.79423-62.0082 57.79423-84.282484 0-25.284848-21.67258-54.181962-55.386393-54.181962-42.743457 0-70.436142 26.489278-82.477374 85.486914l-105.956088-21.67258c24.683144-111.976192 82.477374-157.127486 205.289345-157.127486 98.12985 0 157.72919 63.212631 157.72919 131.842639C707.017407 423.240044 688.956071 461.76953 623.335603 509.329685z</Geometry>
|
||||
<Geometry x:Key="AllGeometry">M 721.005 638.949 C 758.74 638.949 789.333 669.56 789.333 707.312 C 789.333 745.047 758.74 775.657 721.005 775.657 C 683.253 775.657 652.66 745.047 652.66 707.312 C 652.66 669.56 683.253 638.949 721.005 638.949 Z M 512.017 638.949 C 549.77 638.949 580.38 669.56 580.38 707.312 C 580.38 745.047 549.77 775.657 512.017 775.657 C 474.265 775.657 443.672 745.047 443.672 707.312 C 443.672 669.56 474.265 638.949 512.017 638.949 Z M 303.029 638.949 C 340.781 638.949 371.392 669.56 371.392 707.312 C 371.392 745.047 340.781 775.657 303.029 775.657 C 265.277 775.657 234.667 745.047 234.667 707.312 C 234.667 669.56 265.277 638.949 303.029 638.949 Z M 721.005 443.655 C 758.74 443.655 789.333 474.265 789.333 512.017 C 789.333 549.769 758.74 580.363 721.005 580.363 C 683.253 580.363 652.66 549.769 652.66 512.017 C 652.66 474.265 683.253 443.655 721.005 443.655 Z M 512.017 443.655 C 549.77 443.655 580.38 474.265 580.38 512.017 C 580.38 549.769 549.77 580.363 512.017 580.363 C 474.265 580.363 443.672 549.769 443.672 512.017 C 443.672 474.265 474.265 443.655 512.017 443.655 Z M 303.029 443.655 C 340.781 443.655 371.392 474.265 371.392 512.017 C 371.392 549.769 340.781 580.363 303.029 580.363 C 265.277 580.363 234.667 549.769 234.667 512.017 C 234.667 474.265 265.277 443.655 303.029 443.655 Z M 721.005 248.343 C 758.74 248.343 789.333 278.953 789.333 316.688 C 789.333 354.44 758.74 385.051 721.005 385.051 C 683.253 385.051 652.66 354.44 652.66 316.688 C 652.66 278.953 683.253 248.343 721.005 248.343 Z M 512.017 248.343 C 549.77 248.343 580.38 278.953 580.38 316.688 C 580.38 354.44 549.77 385.051 512.017 385.051 C 474.265 385.051 443.672 354.44 443.672 316.688 C 443.672 278.953 474.265 248.343 512.017 248.343 Z M 303.029 248.343 C 340.781 248.343 371.392 278.953 371.392 316.688 C 371.392 354.44 340.781 385.051 303.029 385.051 C 265.277 385.051 234.667 354.44 234.667 316.688 C 234.667 278.953 265.277 248.343 303.029 248.343 Z</Geometry>
|
||||
<Geometry x:Key="DragGeometry">M384 896C384 825.307552 440.814697 768 512 768 582.692448 768 640 824.814694 640 896 640 966.692448 583.185303 1024 512 1024 441.307552 1024 384 967.185306 384 896ZM384 512C384 441.307552 440.814697 384 512 384 582.692448 384 640 440.814697 640 512 640 582.692448 583.185303 640 512 640 441.307552 640 384 583.185303 384 512ZM384 128C384 57.307552 440.814697 0 512 0 582.692448 0 640 56.814697 640 128 640 198.692448 583.185303 256 512 256 441.307552 256 384 199.185303 384 128Z</Geometry>
|
||||
<Geometry x:Key="DropperGeometry">M798.165333 97.834667a42.624 42.624 0 0 0-60.330666 0l-140.629334 140.629333-55.381333-55.296-60.330667 60.330667 55.381334 55.296-353.706667 353.706666a42.709333 42.709333 0 0 0-11.221333 19.84l-42.666667 170.666667a42.538667 42.538667 0 0 0 51.712 51.712l170.666667-42.666667c7.509333-1.877333 14.378667-5.76 19.84-11.221333l353.792-353.792 55.210666 55.125333 60.330667-60.330666-55.210667-55.125334 140.544-140.544a42.624 42.624 0 0 0 0-60.330666l-128-128zM319.488 772.138667l-90.197333 22.570666 22.570666-90.197333 345.386667-345.386667 67.669333 67.584-345.429333 345.429334z</Geometry>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -50,7 +50,7 @@
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="controls:StatusSwitchElement.HiddenElement" Value="True"/>
|
||||
<Condition Property="controls:StatusSwitchElement.HideUncheckedElement" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Visibility" Value="Collapsed" TargetName="UnCheckedElement"/>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../Basic/Converters.xaml"/>
|
||||
<ResourceDictionary Source="Button.xaml"/>
|
||||
<ResourceDictionary Source="Base/ListBoxBaseStyle.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style x:Key="ClockRadioButtonStyle" TargetType="controls:ClockRadioButton">
|
||||
@@ -94,7 +95,7 @@
|
||||
</Canvas>
|
||||
<controls:ClockRadioButton Background="{DynamicResource PrimaryBrush}" Grid.Column="0" x:Name="PART_ButtonAm" IsChecked="True" Height="30" Width="30" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="16,0,0,16" Content="{x:Static langs:Lang.Am}" Style="{StaticResource ClockRadioButtonStyle}"/>
|
||||
<controls:ClockRadioButton Background="{DynamicResource PrimaryBrush}" Grid.Column="2" x:Name="PART_ButtonPm" Height="30" Width="30" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,16,16" Content="{x:Static langs:Lang.Pm}" Style="{StaticResource ClockRadioButtonStyle}"/>
|
||||
<Button Grid.Column="1" Visibility="{TemplateBinding ShowConfirmButton,Converter={StaticResource Boolean2VisibilityConverter}}" Name="PART_ButtonConfirm" Content="{x:Static langs:Lang.Confirm}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" Margin="0,0,0,19" Height="24" Width="60" VerticalAlignment="Bottom" Background="Transparent" Style="{StaticResource ButtonCustom}"/>
|
||||
<Button Grid.Column="1" Visibility="{TemplateBinding ShowConfirmButton,Converter={StaticResource Boolean2VisibilityConverter}}" Name="PART_ButtonConfirm" Content="{x:Static langs:Lang.Confirm}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" Margin="0,0,0,19" Height="24" Width="60" VerticalAlignment="Bottom" Background="Transparent" Style="{StaticResource ButtonCustom}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
@@ -103,5 +104,76 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ClockListBoxItemStyle" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItemBaseStyle}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="true">
|
||||
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="true">
|
||||
<Setter Property="Background" Value="{DynamicResource PrimaryBrush}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="false">
|
||||
<Setter Property="Opacity" Value=".4"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:EdgeElement.ShowEdgeContent" Value="true">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ContentControl Width="16" Height="16" Content="{Binding Path=(controls:EdgeElement.LeftContent),RelativeSource={RelativeSource TemplatedParent}}"/>
|
||||
<ContentPresenter Margin="6,0,0,0" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ClockListBoxStyle" TargetType="ListBox" BasedOn="{StaticResource ListBoxBaseStyle}">
|
||||
<Setter Property="MaxHeight" Value="192"/>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="ItemContainerStyle" Value="{StaticResource ClockListBoxItemStyle}"/>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="controls:ListClock">
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||
<Setter Property="Width" Value="210"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="controls:TitleElement.Background" Value="{DynamicResource TitleBrush}"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:ListClock">
|
||||
<Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox x:Name="PART_HourList" Style="{StaticResource ClockListBoxStyle}"/>
|
||||
<ListBox Grid.Row="0" Grid.Column="1" x:Name="PART_MinuteList" Style="{StaticResource ClockListBoxStyle}" BorderThickness="1,0"/>
|
||||
<ListBox Grid.Row="0" Grid.Column="2" x:Name="PART_SecondList" Style="{StaticResource ClockListBoxStyle}"/>
|
||||
<Border VerticalAlignment="Bottom" Visibility="{Binding Visibility,ElementName=PART_ButtonConfirm}" Height="1" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="{DynamicResource BorderBrush}"/>
|
||||
<Button Margin="0,10" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Visibility="{TemplateBinding ShowConfirmButton,Converter={StaticResource Boolean2VisibilityConverter}}" Name="PART_ButtonConfirm" Content="{x:Static langs:Lang.Confirm}" Foreground="{DynamicResource PrimaryBrush}" HorizontalAlignment="Center" Background="Transparent" Style="{StaticResource ButtonCustom}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -9,6 +9,7 @@
|
||||
<ResourceDictionary Source="../Basic/Converters.xaml"/>
|
||||
<ResourceDictionary Source="Slider.xaml"/>
|
||||
<ResourceDictionary Source="Button.xaml"/>
|
||||
<ResourceDictionary Source="ToggleButton.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style TargetType="controls:ColorPicker">
|
||||
@@ -63,19 +64,26 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="28"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Width="60" Height="32" CornerRadius="2" Background="{StaticResource ColorPickerOpacityBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"/>
|
||||
<Border Grid.Row="0" Grid.Column="0" Width="60" Height="32" CornerRadius="2" Background="{TemplateBinding SelectedBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"/>
|
||||
<Slider Name="PART_SliderColor" LargeChange="0.01" SmallChange="0.01" Grid.ColumnSpan="2" Value="6" Maximum="6" Background="{StaticResource ColorPickerRainbowBrush}" Margin="10,1,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"/>
|
||||
<Slider Name="PART_SliderOpacity" Grid.ColumnSpan="2" IsSnapToTickEnabled="True" Value="{Binding ChannelA,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" Maximum="255" SmallChange="1" Foreground="{TemplateBinding SelectedBrushWithoutOpacity}" Background="{StaticResource ColorPickerOpacityBrush}" Margin="10,0,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Bottom" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"/>
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,14,0,0" VerticalAlignment="Top" Visibility="{Binding ShowList[0],RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}">
|
||||
<ToggleButton Name="PART_ButtonDropper" Width="16" Height="16" Margin="0,0,10,0" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HideUncheckedElement="True">
|
||||
<Path Data="{StaticResource DropperGeometry}" Fill="{DynamicResource PrimaryTextBrush}"/>
|
||||
<controls:StatusSwitchElement.CheckedElement>
|
||||
<Path Data="{StaticResource DropperGeometry}" Fill="{DynamicResource DarkPrimaryBrush}"/>
|
||||
</controls:StatusSwitchElement.CheckedElement>
|
||||
</ToggleButton>
|
||||
<Border Grid.Row="0" Grid.Column="1" Width="32" Height="32" CornerRadius="16" Background="{StaticResource ColorPickerOpacityBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"/>
|
||||
<Border Grid.Row="0" Grid.Column="1" Width="32" Height="32" CornerRadius="16" Background="{TemplateBinding SelectedBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"/>
|
||||
<Slider Name="PART_SliderColor" LargeChange="0.01" SmallChange="0.01" Grid.ColumnSpan="2" Value="6" Maximum="6" Background="{StaticResource ColorPickerRainbowBrush}" Margin="2,1,0,0" Grid.Row="0" Grid.Column="2" VerticalAlignment="Top" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"/>
|
||||
<Slider Name="PART_SliderOpacity" Grid.ColumnSpan="2" IsSnapToTickEnabled="True" Value="{Binding ChannelA,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" Maximum="255" SmallChange="1" Foreground="{TemplateBinding SelectedBrushWithoutOpacity}" Background="{StaticResource ColorPickerOpacityBrush}" Margin="2,0,0,0" Grid.Row="0" Grid.Column="2" VerticalAlignment="Bottom" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"/>
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,14,0,0" VerticalAlignment="Top" Visibility="{Binding ShowList[0],RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}">
|
||||
<TextBox Padding="0" HorizontalContentAlignment="Center" Width="176" Text="{Binding SelectedBrush,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay,Converter={StaticResource Color2HexStrConverter},UpdateSourceTrigger=LostFocus}" FontSize="10" MaxLength="10" Height="24" />
|
||||
<TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="HEX" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<UniformGrid Name="PART_PanelRgb" Visibility="{Binding ShowList[1],RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Rows="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="-2,14,-2,0" VerticalAlignment="Top">
|
||||
<UniformGrid Name="PART_PanelRgb" Visibility="{Binding ShowList[1],RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Rows="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="-2,14,-2,0" VerticalAlignment="Top">
|
||||
<StackPanel Margin="2,0">
|
||||
<controls:NumericUpDown HorizontalContentAlignment="Center" Padding="2,0" Tag="R" Value="{Binding ChannelR,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" ShowUpDownButton="False" Maximum="255" Minimum="0" FontSize="10" Height="24" />
|
||||
<TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="R" HorizontalAlignment="Center"/>
|
||||
@@ -93,7 +101,7 @@
|
||||
<TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="A" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
</UniformGrid>
|
||||
<Button Command="interactivity:ControlCommands.Switch" Padding="6" FontSize="8" BorderThickness="0" HorizontalAlignment="Right" Height="24" Width="20" Grid.Column="2" Grid.Row="1">
|
||||
<Button Command="interactivity:ControlCommands.Switch" Padding="6" FontSize="8" BorderThickness="0" HorizontalAlignment="Right" Height="24" Width="20" Grid.Column="3" Grid.Row="1">
|
||||
<Button.Content>
|
||||
<Path Fill="#323534" Style="{StaticResource UpDownPathStyle}"/>
|
||||
</Button.Content>
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="controls:StatusSwitchElement.HiddenElement" Value="True"/>
|
||||
<Condition Property="controls:StatusSwitchElement.HideUncheckedElement" Value="True"/>
|
||||
<Condition Property="IsChecked" Value="True"/>
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Visibility" Value="Collapsed" TargetName="UnCheckedElement"/>
|
||||
|
||||
@@ -4,8 +4,9 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using HandyControl.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Data
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
internal class ImageAnimator
|
||||
{
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
internal class MouseHook
|
||||
{
|
||||
public static event EventHandler<MouseHookEventArgs> StatusChanged;
|
||||
|
||||
private static IntPtr HookId = IntPtr.Zero;
|
||||
|
||||
private static readonly UnsafeNativeMethods.HookProc Proc = HookCallback;
|
||||
|
||||
public static void Start() => HookId = SetHook(Proc);
|
||||
|
||||
public static void Stop() => UnsafeNativeMethods.UnhookWindowsHookEx(HookId);
|
||||
|
||||
private static IntPtr SetHook(UnsafeNativeMethods.HookProc proc)
|
||||
{
|
||||
using (var curProcess = Process.GetCurrentProcess())
|
||||
using (var curModule = curProcess.MainModule)
|
||||
{
|
||||
if (curModule != null)
|
||||
{
|
||||
return UnsafeNativeMethods.SetWindowsHookEx((int) UnsafeNativeMethods.HookType.WH_MOUSE_LL, proc,
|
||||
UnsafeNativeMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
if (nCode < 0) return UnsafeNativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam);
|
||||
var hookStruct = (UnsafeNativeMethods.MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(UnsafeNativeMethods.MOUSEHOOKSTRUCT));
|
||||
StatusChanged?.Invoke(null, new MouseHookEventArgs
|
||||
{
|
||||
Message = (MouseHookMessageType)wParam,
|
||||
Point = new NativeMethods.POINT(hookStruct.pt.X, hookStruct.pt.Y)
|
||||
});
|
||||
|
||||
return UnsafeNativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,5 +174,45 @@ namespace HandyControl.Tools.Interop
|
||||
|
||||
[DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(ExternDll.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
|
||||
public enum HookType
|
||||
{
|
||||
WH_MOUSE_LL = 14,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MOUSEHOOKSTRUCT
|
||||
{
|
||||
public NativeMethods.POINT pt;
|
||||
public IntPtr hwnd;
|
||||
public uint wHitTestCode;
|
||||
public IntPtr dwExtraInfo;
|
||||
}
|
||||
|
||||
public delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr GetWindowDC(IntPtr window);
|
||||
|
||||
[DllImport(ExternDll.Gdi32, SetLastError = true)]
|
||||
public static extern uint GetPixel(IntPtr dc, int x, int y);
|
||||
|
||||
[DllImport(ExternDll.User32, SetLastError = true)]
|
||||
public static extern int ReleaseDC(IntPtr window, IntPtr dc);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user