我正在尝试创建一个方形图(X轴宽度与Y轴高度相同).
我找不到任何关于此的文档,我看到的所有可能无法访问的属性都无法访问.
我试过了:
<oxy:PlotView Model="{Binding Model}" Width="500" Height="500"/>
Run Code Online (Sandbox Code Playgroud)
这显然不起作用,因为这设置了整个区域(而不是图形特定部分).
我通过挂钩LayoutUpdated事件并根据宽度/高度差异PlotView更新来解决了这个问题。PlotView.WidthPlotArea
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>
Run Code Online (Sandbox Code Playgroud)
背后代码:
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)