Search code examples
c#wpfoxyplot

How to reset zoom oxyplot c# wpf


I have an oxyplot RectangleBarSeries and a button "Reset". When I press the button I want the zoom to reset (in the same way the zoom resets when A is pressed on the keyboard).

I have tried to achieve this by adding an eventhandler with the following code in my MainPanel.xaml.cs:

private void Reset_Click(object sender, RoutedEventArgs e)
    {
       histogram.PlotModel.Axes[0].Reset();
       histogram.PlotModel.Axes[1].Reset(); 
    } 

but get the error "myNameSpace.Histogram does not contain a definition for PlotModel and no extension method "PlotModel" accepting a first argument of type myNameSpace.Histogram could be found".

What should I write instead to be able to reset the zoom on my plot?

Part of my Histogram class:

namespace myNameSpace
{
    public class Histogram : INotifyPropertyChanged
    {
    public Collection<Item> Items { get; set; }
    private PlotModel histogramModel;
    public PlotModel HistogramModel
    {
        get { return histogramModel; }
        set { histogramModel = value; OnPropertyChanged("HistogramModel"); }
    }

    public class Item
    {
        public string Label { get; set; }
        public double Value { get; set; }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    //NotifyPropertyChangedInvocator
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public Histogram(List<double> frequency, List<double> axis, string VariableName)
    {
        CreateRectangleBar(frequency, axis, VariableName);
    }

Solution

  • Try to use MyPlotViewName.ResetAllAxes(); instead, that should work.