前端:
<local:TouchPlot Grid.Row="1" x:Name="pv" local:ShowTrackerAndLeaveOpenBehavior.BindToMouseDown="Left" Margin="0,0,5,0" />
如果你是后台写,就这样:
TouchPlot plt = new TouchPlot { Model = GetPlot() };//GetPlot()是自定义方法
ShowTrackerAndLeaveOpenBehavior.SetBindToMouseDown(plt, OxyMouseButton.Left);
自定义的类
public class TouchPlot : PlotView
{
protected override void OnTouchDown(TouchEventArgs e)
{
var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
args.RoutedEvent = PreviewMouseLeftButtonDownEvent;
args.Source = e.OriginalSource;
RaiseEvent(args);
e.Handled = true;
}
}
public static class ShowTrackerAndLeaveOpenBehavior
{
public static readonly DependencyProperty BindToMouseDownProperty = DependencyProperty.RegisterAttached(
"BindToMouseDown", typeof(OxyMouseButton), typeof(ShowTrackerAndLeaveOpenBehavior),
new PropertyMetadata(default(OxyMouseButton), OnBindToMouseButtonChanged));
[AttachedPropertyBrowsableForType(typeof(IPlotView))]
public static void SetBindToMouseDown(DependencyObject element, OxyMouseButton value) =>
element.SetValue(BindToMouseDownProperty, value);
[AttachedPropertyBrowsableForType(typeof(IPlotView))]
public static OxyMouseButton GetBindToMouseDown(DependencyObject element) =>
(OxyMouseButton)element.GetValue(BindToMouseDownProperty);
private static void OnBindToMouseButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is IPlotView plot))

文章描述了一个在前端图形库中实现自定义触摸事件绑定和追踪器行为的示例。通过TouchPlotGrid组件,设置了BindToMouseDown属性以响应左侧鼠标点击,并使用ShowTrackerAndLeaveOpenBehavior类来控制追踪器的行为,包括在鼠标按下时显示并保持追踪器打开。代码中还包括了后台如何设置这一行为以及相关的事件处理和控制器操作。
最低0.47元/天 解锁文章

14万+





