I want to make Rectangle that would not scale size after axis changing. After changing X And Y minimum or maximum, OxyPlot scaling Rectangle. And i don't know the "new" minimum and maximum of X and Y Axes. Is it simple way to do this?
using GalaSoft.MvvmLight.Command;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication22
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new PlotRectangle();
}
}
public class PlotRectangle
{
public ICommand ComboCommand { get; set; }
public PlotModel PlotModel { get; set; }
public LinearAxis XAxis { get; set; }
public LinearAxis YAxis { get; set; }
public LineSeries LineSeries { get; set; }
public RectangleAnnotation Rect {get;set;}
public List<string> Items { get; set; }
public PlotRectangle()
{
ComboCommand = new RelayCommand(()=>ChangeAxis());
PlotModel = new PlotModel();
Rect = new RectangleAnnotation();
LineSeries = new LineSeries();
Items = new List<string>();
Items.Add("5");
Items.Add("10");
Items.Add("15");
Rect.MinimumX = 10;
Rect.MaximumX = 20;
Rect.MinimumY = 1;
Rect.MaximumY = 10;
XAxis = new LinearAxis
{
Position=AxisPosition.Bottom,
};
YAxis = new LinearAxis
{
Position = AxisPosition.Left
};
PlotModel.Axes.Add(XAxis);
PlotModel.Axes.Add(YAxis);
PlotModel.Series.Add(LineSeries);
PlotModel.Annotations.Add(Rect);
}
public void ChangeAxis()
{
Random rnd1 = new Random();
Random rnd2 = new Random();
Random rnd3 = new Random();
Random rnd4 = new Random();
PlotModel.Axes[1] = new LinearAxis
{
Minimum=rnd1.Next(1,10),
Maximum=rnd2.Next(15,50)
};
PlotModel.Axes[0] = new LinearAxis
{
Minimum = rnd3.Next(1, 10),
Maximum = rnd4.Next(15, 50)
};
PlotModel.InvalidatePlot(true);
}
}
}
And Xaml look like this
<Window x:Class="WpfApplication22.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:oxy="http://oxyplot.org/wpf"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Horizontal">
<ComboBox Height="20" VerticalAlignment="Top" SelectedIndex="0" ItemsSource="{Binding Items}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ComboCommand}"></i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Grid>
<oxy:Plot Model="{Binding PlotModel}" Width="490"></oxy:Plot>
</Grid>
</StackPanel>
I need to draw on Screen, but how?