2017-08-04 93 views
6

我正在嘗試創建一個方形圖(X軸寬度與Y軸高度相同)。如何使用Oxyplot創建方形圖區域

我找不到任何有關此文檔以及我所見過的所有可能能夠執行此操作的屬性都無法訪問。

我已經試過:

<oxy:PlotView Model="{Binding Model}" Width="500" Height="500"/> 

這顯然是行不通的,因爲這將整個區域(而不是圖特定部分)。

回答

2

我通過鉤入在PlotViewLayoutUpdated事件並從PlotArea寬度/高度差更新所述PlotView.Width解決了這個。

XAML:

<Window x:Class="Temp.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" 
     Title="MainWindow" Width="500" Height="500"> 
    <Grid> 
     <oxy:PlotView Model="{Binding PlotModel}" x:Name="PlotView"/> 
    </Grid> 
</Window> 

代碼背後:

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; 
      } 
     } 
    } 
-1

如何使用元素以外定義繪圖區域的寬度和高度,像電網邊境

<Border width="500" height="500"> 
    <oxy:PlotView Model="{Binding Model}" /> 
</Border> 
+0

這將控制以具有這些尺寸,而不是特定的圖形(X/Y軸長度)部分。 – gleng

0

假設你不希望它是可調整大小,它的工作原理,如果你用Height將其包裝在Border中,其等於Width加上標題部分的高度。例如:

XAML:

<Window x:Class="MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:oxy="http://oxyplot.org/wpf" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Border Width="200" Height="224"> 
      <oxy:PlotView x:Name="plot" Model="{Binding Path=PlotModel}"/> 
     </Border> 
    </Grid> 
</Window> 

代碼隱藏模型對象:

using OxyPlot; 
using OxyPlot.Series; 
using System.Windows; 

/// <summary> 
/// Interaction logic for MainWindow.xaml 
/// </summary> 
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); 
    } 
} 

這是什麼樣子: the window

如果你想要做的可調整大小的版本,然後使用包含窗口的SizeChanged事件,並重新調整包含Border的大小呃在那個事件處理程序。

相關問題