绑定OxyPlot Tracker并在TextBlock中设置获取值

问题描述 投票:0回答:2

项目 - WPF,C#,IDE - Visual Studio。我想在我的PlotView上进行绑定值跟踪。我的代码XAML:

 <Border CornerRadius="6" BorderBrush="Gray" BorderThickness="4" Grid.Column="0" Grid.ColumnSpan="2">
        <oxy:PlotView Background="White" Model="{Binding GraphicModel.Model}"  >

        </oxy:PlotView>
    </Border>

    <TextBlock Text="{Binding CurrentTrackerValue}" Grid.Column="0" Grid.Row="1"/>

我知道,PlotView.Model有什么事件TrackerChange。如何使用此活动? P.S。:我使用模式MVVM,所以我想使用命令而不是事件。谢谢!

c# wpf xaml mvvm oxyplot
2个回答
1
投票

如果我正确理解您的要求,您希望每次更新跟踪器时更新TextBlock。我相信你跟踪了TrackerChanged活动。您可以在ViewModel中执行以下操作,您将在其中创建PlotModel实例,该实例将绑定到OxyPlot Graph

PlotModelName.TrackerChanged += (sender, eventArgs)=>
{
  CurrentTrackerValue = eventArgs.HitResult != null ? eventArgs.HitResult.Text : CurrentTrackerValue;
  NotifyPropertyChanged(nameof(CurrentTrackerValue));
};

其中CurrentTrackerValue定义为

public string CurrentTrackerValue { get; set; }

这将确保每次通过TrackerChangedEvent更改Tracker时都会更新CurrentTrackerValue属性


1
投票

伙计们谢谢它的工作步骤吼叫:)

.NET 4.7.2

  1. 我添加了INotifyPropertyChanged

      public string CurrentTrackerValueX { get; set; }
      public string CurrentTrackerValueY { get; set; }

  1. 然后生成

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) 
    { 
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
    }

  1. 然后我按照你的想法

    pm.TrackerChanged += (sender, eventArgs) =>
    {
        string CurrentTrackerValue = "";
        CurrentTrackerValue = eventArgs.HitResult != null ? eventArgs.HitResult.Text : CurrentTrackerValue;
        if (!String.IsNullOrEmpty(CurrentTrackerValue))
        {
            var x = Regex.Matches(CurrentTrackerValue, "([0-9]*,[0-9]*)");
            CurrentTrackerValueX = x[0].Value;
            CurrentTrackerValueY = x[1].Value;
            OnPropertyChanged(nameof(CurrentTrackerValueX));
            OnPropertyChanged(nameof(CurrentTrackerValueY));
        }
    };

离开Tracker后,If loop是文本框中需要null值的原因,他仍然希望给文本框赋予null。

全部完成并使用这种类型的字符串:)


    editcurrentLineSeries[i].TrackerFormatString = "{0}\n{1}: {2:0.00}\n{3}: {4:0.00}";

© www.soinside.com 2019 - 2024. All rights reserved.