[ColorPicker]Fix "Failed to get mouse position-1,1" warning (#20291)

* ColorPicker-17636: Fix warning "Failed to get ... mouse position-1,1"

* retrigger checks

* retrigger checks
This commit is contained in:
Taras 2022-09-28 12:38:18 +03:00 коммит произвёл GitHub
Родитель 123269ea5e
Коммит 4e20ae07ca
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 21 добавлений и 4 удалений

Просмотреть файл

@ -19,7 +19,6 @@ namespace ColorPicker.Behaviors
private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
{
Appear();
AssociatedObject.IsVisibleChanged += AssociatedObject_IsVisibleChanged;
}

Просмотреть файл

@ -19,5 +19,7 @@ namespace ColorPicker.Mouse
event MouseUpEventHandler OnMouseDown;
System.Windows.Point CurrentPosition { get; }
Color CurrentColor { get; }
}
}

Просмотреть файл

@ -42,6 +42,8 @@ namespace ColorPicker.Mouse
_mouseHook = new MouseHook();
_userSettings = userSettings;
_userSettings.CopiedColorRepresentation.PropertyChanged += CopiedColorRepresentation_PropertyChanged;
_previousMousePosition = GetCursorPosition();
_previousColor = GetPixelColor(_previousMousePosition);
}
public event EventHandler<Color> MouseColorChanged;
@ -60,6 +62,14 @@ namespace ColorPicker.Mouse
}
}
public Color CurrentColor
{
get
{
return _previousColor;
}
}
private void Timer_Tick(object sender, EventArgs e)
{
UpdateMouseInfo();

Просмотреть файл

@ -67,6 +67,7 @@ namespace ColorPicker.ViewModels
if (mouseInfoProvider != null)
{
SetColorDetails(mouseInfoProvider.CurrentColor);
mouseInfoProvider.MouseColorChanged += Mouse_ColorChanged;
mouseInfoProvider.OnMouseDown += MouseInfoProvider_OnMouseDown;
mouseInfoProvider.OnMouseWheel += MouseInfoProvider_OnMouseWheel;
@ -132,9 +133,7 @@ namespace ColorPicker.ViewModels
/// <param name="color">The new <see cref="Color"/> under the mouse cursor</param>
private void Mouse_ColorChanged(object sender, System.Drawing.Color color)
{
ColorBrush = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
ColorText = ColorRepresentationHelper.GetStringRepresentation(color, _userSettings.CopiedColorRepresentation.Value);
ColorName = ColorNameHelper.GetColorName(color);
SetColorDetails(color);
}
/// <summary>
@ -172,6 +171,13 @@ namespace ColorPicker.ViewModels
return color.A + "|" + color.R + "|" + color.G + "|" + color.B;
}
private void SetColorDetails(System.Drawing.Color color)
{
ColorBrush = new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
ColorText = ColorRepresentationHelper.GetStringRepresentation(color, _userSettings.CopiedColorRepresentation.Value);
ColorName = ColorNameHelper.GetColorName(color);
}
/// <summary>
/// Tell the color picker that the user have used the mouse wheel
/// </summary>