mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:26:31 +00:00
38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace Azaion.Annotator.Controls
|
|
{
|
|
public class UpdatableProgressBar : ProgressBar
|
|
{
|
|
public delegate void ValueChange(double oldValue, double newValue);
|
|
|
|
public new event ValueChange? ValueChanged;
|
|
|
|
public UpdatableProgressBar() : base()
|
|
{
|
|
MouseDown += OnMouseDown;
|
|
MouseMove += OnMouseMove;
|
|
}
|
|
|
|
private double SetProgressBarValue(double mousePos)
|
|
{
|
|
Value = Minimum;
|
|
var pbValue = mousePos / ActualWidth * Maximum;
|
|
ValueChanged?.Invoke(Value, pbValue);
|
|
return pbValue;
|
|
}
|
|
|
|
private void OnMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
Value = SetProgressBarValue(e.GetPosition(this).X);
|
|
}
|
|
|
|
private void OnMouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
|
Value = SetProgressBarValue(e.GetPosition(this).X);
|
|
}
|
|
}
|
|
}
|