oxyplot 点击x,y交汇的点,标签一直显示

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

       前端:

<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))
 
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值