如何使用Oxyplot创建方形区域

我正在尝试创建一个方形图(X轴宽度与Y轴高度相同)。

我找不到任何关于此的文档,我看到的所有可能无法访问的属性都无法访问。

我试过了:

 

这显然不起作用,因为这会设置整个区域(而不是图形特定部分)。

我通过挂钩LayoutUpdated上的LayoutUpdated事件并从PlotArea宽度/高度差更新PlotView.Width来解决这个问题。

XAML:

      

代码背后:

 public partial class MainWindow { public MainWindow() { InitializeComponent(); DataContext = new MainViewModel(); } public override void OnApplyTemplate() { base.OnApplyTemplate(); var plotView = (PlotView) this.FindName("PlotView"); plotView.LayoutUpdated += OnLayoutUpdated; } private void OnLayoutUpdated(object sender, EventArgs e) { var plotView = (PlotView) this.FindName("PlotView") ; if (plotView.Model != null) { var widthAdjustment = plotView.Model.PlotArea.Width - plotView.Model.PlotArea.Height; plotView.Width = plotView.ActualWidth - widthAdjustment; } } } 

假设您不希望它可以resize,如果您将其包装在Height等于Width加上标题部分高度的Border ,则它会起作用。 例如:

XAML:

        

Model对象的代码隐藏:

 using OxyPlot; using OxyPlot.Series; using System.Windows; ///  /// Interaction logic for MainWindow.xaml ///  public partial class MainWindow : Window { public PlotModel Model { get; set; } public MainWindow() { DataContext = this; Model = new PlotModel { Title = "Test", TitlePadding = 0, TitleFontSize = 24 }; LineSeries line = new LineSeries(); line.Points.Add(new DataPoint(0, 0)); line.Points.Add(new DataPoint(1, 1)); line.Points.Add(new DataPoint(2, 2)); Model.Series.Add(line); } } 

这就是它的样子: 窗户

如果要执行可resize的版本,请使用包含窗口的SizeChanged事件,并在该事件处理程序中重新调整Border容器的大小。

如何使用外部元素来定义绘图区域的宽度和高度,如网格边框