C# 如何在更改轴后保持矩形大小不变
我想制作一个在轴改变后不会缩放大小的矩形。 更改X和Y最小值或最大值后,OxyPlot缩放矩形。 我不知道X轴和Y轴的“新”最小值和最大值。这样做简单吗C# 如何在更改轴后保持矩形大小不变,c#,wpf,oxyplot,C#,Wpf,Oxyplot,我想制作一个在轴改变后不会缩放大小的矩形。 更改X和Y最小值或最大值后,OxyPlot缩放矩形。 我不知道X轴和Y轴的“新”最小值和最大值。这样做简单吗 using GalaSoft.MvvmLight.Command; using OxyPlot; using OxyPlot.Annotations; using OxyPlot.Axes; using OxyPlot.Series; using System; using System.Collections.Generic; using S
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);
}
}
}
使用GalaSoft.MvvmLight.Command;
使用氧图;
使用OxyPlot.注释;
使用OxyPlot.Axes;
使用OxyPlot.系列;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间WpfApplication22
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
DataContext=新建PlotRectangle();
}
}
公共类绘图矩形
{
公共ICommand命令{get;set;}
公共PlotModel PlotModel{get;set;}
public LinearAxis XAxis{get;set;}
public LinearAxis YAxis{get;set;}
公共线条系列线条系列{get;set;}
公共矩形注释Rect{get;set;}
公共列表项{get;set;}
公共绘图矩形()
{
ComboCommand=newrelayCommand(()=>ChangeAxis());
PlotModel=新的PlotModel();
Rect=新的矩形注释();
LineSeries=新的LineSeries();
项目=新列表();
项目。添加(“5”);
项目。添加(“10”);
项目。添加(“15”);
Rect.MinimumX=10;
Rect.MaximumX=20;
Rect.MinimumY=1;
Rect.MaximumY=10;
XAxis=新的线性轴
{
位置=AxisPosition.Bottom,
};
YAxis=新的线性轴
{
位置=轴位置。左
};
PlotModel.axis.Add(XAxis);
PlotModel.axis.Add(YAxis);
PlotModel.Series.Add(LineSeries);
PlotModel.Annotations.Add(Rect);
}
public void ChangeAxis()
{
随机rnd1=新随机();
随机rnd2=新随机();
随机rnd3=新随机();
随机rnd4=新随机();
PlotModel.Axes[1]=新的线性轴
{
最小值=rnd1。下一个(1,10),
最大值=rnd2。下一个(15,50)
};
PlotModel.Axes[0]=新的线性轴
{
最小值=rnd3。下一个(1,10),
最大值=rnd4。下一个(15,50)
};
PlotModel.InvalidatePlot(真);
}
}
}
Xaml看起来像这样
<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>
我需要在屏幕上画画,但是怎么画呢