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

       前端:

<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))
                throw new InvalidOperationException($"Can only be applied to {nameof(IPlotView)}");

            //if (plot.ActualModel == null)
            //    throw new InvalidOperationException("Plot has no model");

            var controller = plot.ActualController;
            if (controller == null)
                throw new InvalidOperationException("Plot has no controller");

            if (e.OldValue is OxyMouseButton oldButton && oldButton != OxyMouseButton.None)
                controller.UnbindMouseDown(oldButton);

            var newButton = GetBindToMouseDown(d);
            if (newButton == OxyMouseButton.None)
                return;

            controller.UnbindMouseDown(newButton);
            controller.BindMouseDown(newButton, new DelegatePlotCommand<OxyMouseDownEventArgs>(
                AddStayOpenTrackerManipulator));
        }

        private static void AddStayOpenTrackerManipulator(IPlotView view, IController controller,
            OxyMouseDownEventArgs e)
        {
            controller.AddMouseManipulator(view, new StayOpenTrackerManipulator(view), e);
        }

        private class StayOpenTrackerManipulator : TrackerManipulator
        {
            private readonly PlotModel _plotModel;
            private bool _isTrackerOpen;

            public StayOpenTrackerManipulator(IPlotView plot)
                : base(plot)
            {
                _plotModel = plot?.ActualModel;

                Snap = true;
                PointsOnly = false;
            }

            public override void Started(OxyMouseEventArgs e)
            {
                if (_plotModel != null) { _plotModel.TrackerChanged += HandleTrackerChanged; }
                base.Started(e);
            }

            public override void Completed(OxyMouseEventArgs e)
            {
                if (!_isTrackerOpen)
                {
                    ReallyCompleted(e);
                }
                else
                {
                    // Completed() is called as soon as the mouse button is released.
                    // We won't call the base Completed() here since that would hide the tracker.
                    // Instead, defer the call until one of the hooked events occurs.
                    // The caller will still remove us from the list of active manipulators as soon as we return,
                    // but that's good; otherwise the tracker would continue to move around as the mouse does.
                    new DeferredCompletedCall(_plotModel, () => ReallyCompleted(e)).HookUp();
                }
            }

            private void ReallyCompleted(OxyMouseEventArgs e)
            {
                base.Completed(e);

                // Must unhook or this object will live as long as the model (instead of as long as the manipulation)
                if (_plotModel != null) { _plotModel.TrackerChanged -= HandleTrackerChanged; }
            }

            private void HandleTrackerChanged(object sender, TrackerEventArgs e) =>
                _isTrackerOpen = e.HitResult != null;

            /// <summary>
            /// Monitors events that should trigger manipulator completion and calls an injected function when they fire
            /// </summary>
            private class DeferredCompletedCall
            {
                private readonly PlotModel _plotModel;
                private readonly Action _completed;

                public DeferredCompletedCall(PlotModel plotModel, Action completed)
                {
                    _plotModel = plotModel;
                    _completed = completed;
                }

                /// <summary>
                /// Start monitoring events. Their observer lists will keep us alive until <see cref="Unhook"/> is called.
                /// </summary>
                public void HookUp()
                {
                    Unhook();

                    _plotModel.MouseDown += HandleMouseDown;
                    _plotModel.Updated += HandleUpdated;
                    _plotModel.MouseLeave += HandleMouseLeave;
                }

                /// <summary>
                /// Stop watching events. If they were the only things keeping us alive, we'll turn into garbage.
                /// </summary>
                private void Unhook()
                {
                    _plotModel.MouseDown -= HandleMouseDown;
                    _plotModel.Updated -= HandleUpdated;
                    _plotModel.MouseLeave -= HandleMouseLeave;
                }

                private void CallCompletedAndUnhookEvents()
                {
                    _completed();
                    Unhook();
                }

                private void HandleUpdated(object sender, EventArgs e) => CallCompletedAndUnhookEvents();

                private void HandleMouseLeave(object sender, OxyMouseEventArgs e) => CallCompletedAndUnhookEvents();

                private void HandleMouseDown(object sender, OxyMouseDownEventArgs e)
                {
                    CallCompletedAndUnhookEvents();

                    // Since we're not setting e.Handled to true here, this click will have its regular effect in
                    // addition to closing the tracker; e.g. it could open the tracker again at the new position.
                    // Modify this code if that's not what you want.
                }
            }
        }
    }

相关推荐

wpf .netcore 导出pdf文件

【代码】wpf .netcore 导出pdf文件。

somethingGoWay的专栏 380

wpf .netcore 导出docx文件

下载nuget包 DocX。

somethingGoWay的专栏 251

wpf .netcore6.0 导出html文件

【代码】wpf .netcore6.0 导出html文件。

somethingGoWay的专栏 138

wpf SerialPortStream 循环串口进行连接仪器

【代码】wpf SerialPortStream 循环串口进行连接仪器。

somethingGoWay的专栏 174

wpf 多个RadioButton公用一个样式,每个显示的图片不一样

【代码】wpf 多个RadioButton公用一个样式,每个显示的图片不一样。

somethingGoWay的专栏 157

wpf 只能输入基数的文本框

【代码】wpf 只能输入基数的文本框。

somethingGoWay的专栏 137

wpf 只能输入int类型的文本框

我做的这个文本框,可设置最大值,最小值,有失去焦点事件的话,失去焦点文本框里的数字是你上次填的数字,避免数据为空的情况。

somethingGoWay的专栏 369

wpf 自定义控件,只能输入小数点,并且能控制小数点位数

调用:DecimalCount就是小数点位数,一般不去设置,最多三位小数点。如果失去焦点,当前的数据会时你上次输入的数据,这样不会出现数据为空的情况。

somethingGoWay的专栏 338

wpf 自定义密码文本框,并且可以双向绑定

【代码】wpf 自定义密码文本框,并且可以双向绑定。

somethingGoWay的专栏 309

wpf 自定义输入ip地址的文本框

PS:因为是上位机,所以文本框里面写了键盘,如果不需要可删除。

somethingGoWay的专栏 311

sqlite dapper 数据量过大,增加索引,写成公用方法。

PS:数据库中索引名称是不能重复的,所以先判断索引是否存在,存在则不会创建索引。

somethingGoWay的专栏 152

Sqlit Dapper根据模型新建表

这样模型中也可写表不用的字段,用来数据绑定等其他用途。还可以做成公用方法便于调用和利用。PS:如果模型中有不需要加到数据库中的字段则加标记。

somethingGoWay的专栏 264

Sqlite 改变已有表中的字段名称

【代码】Sqlite 改变已有表中的字段名称。

somethingGoWay的专栏 249

Sqlite 数据库和表已经建成,投入使用,再在表中增加字段

【代码】sqllite 数据库和表已经建成,投入使用,再在表中增加字段。

somethingGoWay的专栏 289

wpf ListBox中所有文本框回车跳到下个文本框.

我的ListBox有十行三列的文本框,回车会跳到下一个,一列到底回车跳到下一列,到最后一个又会跳到第一个.并且跳到文本框文本框中的文字会被全部选中.代码如下.xmal.cs 这里也可以ListBox的Loaded事件,就不用给ListBox取名字了.暂时还不知这两种有什么区别,哪种更好一点.我用的Mvvm框架.

somethingGoWay的专栏 356

【转】微软教学:三种方法屏蔽Win7/Win8.1升级Win10推送

经 过上述修改,Win7/Win8.1用户的Win10升级通知和升级功能就全部关闭了,不想使用这种方法升级的用户,或者不想被通知打扰的用户可以按照这 些方法操作。用户免费升级到了Win10,不过也有一批用户在升级和使用过程中遇到了严重问题,因而回退到了原来的系统,另外还有一部分用户对新系统还在评估之中,暂时不打算升级。此后,升级Win10的推送功能被关闭,如果用户想升级Win10,需要依靠手动更新,或者再次在组策略开启升级推送功能。,点击“确定”即可(若已关闭升级功能,该项目默认为0)

somethingGoWay的专栏 5万+

wpf .net core6.0 图片打印预览,可以拖拽位置,滚轮放大缩小,打印

接上一篇生成二维码

somethingGoWay的专栏 369

wpf .net core6.0 生成二维码

这是打印预览按钮所在页面。

somethingGoWay的专栏 453

wpf oxyplot 双向绑定 刷新局部数据

首先,声明,我用的是CommunityToolkit.Mvvm框架,大家可以根据自己的实际情况来改。我是根据combobox的选择,来更新plotview的数据。页面plotview双向绑定是这样的。我是初始化页面的时候初始化控件。

somethingGoWay的专栏 835

wpf win8系统popup位置会跑偏

在App.xmal.cs里调用也行,在初始化页面的时候调用也可以.修改弹出菜单相对于相应菜单项是左对齐还是右对齐。

somethingGoWay的专栏 292

wpf Textbox绑定非string类型,经常出现红框

Textbox绑定非string类型,为空会出现红框.失去焦点也会出现红框.用下面方法就不会出现红框,也不会出现xaml绑定错误了.

somethingGoWay的专栏 460

下位机用命令来连接wifi(包括查询wifi,连接wifi,断开wifi,查询wifi状态等)

TextBlock x:Name="NoWlanTextBlock" Grid.Row="1" Text="貌似没有无线网卡" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Red" Visibility="{Binding NoWlan}"/>Content="取消" Background="LightGray" Foreground="Black" Click="BtnClose_Click" />

somethingGoWay的专栏 284

C# log日志

还有LogUtil.Log(ex.Message);

somethingGoWay的专栏 503

C# 更改入站规则,增加端口信息

重点在于c:/Windows/Systm32/FirewallAPI.dll,要将这个dll复制并引用到自己的项目中。//创建firewall管理类的实例。//加入到防火墙的管理策略。/// 将应用程序添加到防火墙例外。//加入到防火墙的管理策略。/// 应用程序可执行文件全路径。/// 删除防火墙例外中应用程序。/// 协议(TCP、UDP)//程序的路径及文件名。/// 协议(TCP、UDP)/// 添加防火墙例外端口。/// 删除防火墙例外端口。/// 程序的绝对路径。/// 应用程序名称。

somethingGoWay的专栏 562

wpf oxyPlot 峰值画线标注

/将线添加到图标的容器中。//将线添加到图标的容器中。IsZoomEnabled = false,//坐标轴缩放关闭。IsPanEnabled = false,//图表缩放功能关闭。IsZoomEnabled = false,//坐标轴缩放关闭。IsPanEnabled = false,//图表缩放功能关闭。

somethingGoWay的专栏 935

C# wpf 修改windows时间设置(有网络和无网络都可)

需要设置的时间返回网络时间

somethingGoWay的专栏 1005

wpf 在程序里关机(关闭电脑)

需要的小伙伴最好写个判断,是否要关机之类的,点击是或者确认才关掉。

somethingGoWay的专栏 477

开机自启动-秒开

2.计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 的Userinit,把启动路径放进去。1.打开注册表 运行窗口 regedit。

somethingGoWay的专栏 169

WPF TextBlock加下划线 并且与字段有间距

如果你不需要设置下划线与字段之间的距离,并且要在后台处理。PenOffset就是设置下划线与字段的距离。如果你不需要设置下划线与字段之间的距离。

somethingGoWay的专栏 1371

查找ListBox里面ListBoxItem

ListBoxItem item = lbDepartment.ItemContainerGenerator.ContainerFromItem(dc) as ListBoxItem; dc是绑定ListBox选中的模型

somethingGoWay的专栏 378
上一篇: wpf oxyPlot 峰值画线标注
下一篇: C# 更改入站规则,增加端口信息
SomethingGoWay
SomethingGoWay 麟角科技 麟角科技
博客等级 码龄15年 18粉丝 54原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值