我正在尝试创建一个方形图(X 轴宽度与 Y 轴高度相同)。
我找不到关于此的任何文档,而且我看到的所有可能能够执行此操作的属性都无法访问。
我试过:
<oxy:PlotView Model="{Binding Model}" Width="500" Height="500"/>
这显然是行不通的,因为它设置了整个区域(不是图形特定部分)。
最佳答案
我通过连接到 LayoutUpdated
解决了这个问题PlotView
上的事件并更新 PlotView.Width
来自 PlotArea
宽度/高度差。
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;
}
}
}
关于c# - 如何使用 Oxyplot 创建正方形绘图区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45513600/