Assuming you don't want it to be resizable, it works if you wrap it in a Border
with a Height
that is equal to the Width
plus the height of the title section. For example:
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>
Code-behind for the Model object:
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);
}
}
And this is what it looks like:
If you want to do a resizable version, then use the containing window's SizeChanged
event, and re-adjust the size of the Border
container in that event handler.