本文整理汇总了C#中System.Windows.Controls.Canvas.CaptureMouse方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.CaptureMouse方法的具体用法?C# Canvas.CaptureMouse怎么用?C# Canvas.CaptureMouse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Canvas
的用法示例。
在下文中一共展示了Canvas.CaptureMouse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnVehicleMouseDown
private void OnVehicleMouseDown(object sender, MouseButtonEventArgs e)
{
_draggedVehicle = (Canvas)sender;
_position = e.GetPosition(this);
e.Handled = true;
_draggedVehicle.CaptureMouse();
}
示例2: OnApplyTemplate
/// <summary>
/// When overridden in a derived class, is invoked whenever application code or internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>.
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_gradientCanvas = Template.FindName("PART_GradientCanvas", this) as Canvas;
_gradientSelector = Template.FindName("PART_GradientSelector", this) as FrameworkElement;
_colorSpectrumSlider = Template.FindName("PART_ColorSpectrumSlider", this) as ColorSpectrumSlider;
_tbA = Template.FindName("PART_TextBoxA", this) as TextBox;
_tbR = Template.FindName("PART_TextBoxR", this) as TextBox;
_tbG = Template.FindName("PART_TextBoxG", this) as TextBox;
_tbB = Template.FindName("PART_TextBoxB", this) as TextBox;
_tbHexString = Template.FindName("PART_TextBoxHexString", this) as TextBox;
if (_gradientCanvas != null)
{
_gradientCanvas.PreviewMouseLeftButtonDown += (o, e) =>
{
var p = e.GetPosition(_gradientCanvas);
UpdateColorByPosition(p);
_gradientCanvas.CaptureMouse();
e.Handled = true;
};
_gradientCanvas.MouseMove += (o, e) =>
{
if (_gradientCanvas.IsMouseCaptured && e.LeftButton == MouseButtonState.Pressed)
{
var position = e.GetPosition(_gradientCanvas);
UpdateColorByPosition(position);
}
};
_gradientCanvas.MouseLeftButtonUp += (o, e) =>
{
_gradientCanvas.ReleaseMouseCapture();
};
_gradientCanvas.SizeChanged += (o, e) =>
{
var hslColor = _lastPreciseColor ?? HslColor.FromArgb(Color);
hslColor.H = _colorSpectrumSlider.Value;
UpdateColor(hslColor.ToArgb(), hslColor);
};
}
if (_colorSpectrumSlider != null)
{
_colorSpectrumSlider.ValueChanged += (o, e) =>
{
var hslColor = _lastPreciseColor ?? HslColor.FromArgb(Color);
hslColor.H = _colorSpectrumSlider.Value;
UpdateColor(hslColor.ToArgb(), hslColor);
};
}
UpdateColor(Color, null);
}