c# - 如何使用 Oxyplot 创建正方形绘图区域

标签 c# wpf oxyplot

我正在尝试创建一个方形图(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/

相关文章:

c# - 反射 - 将一个委托(delegate)添加到另一个委托(delegate)的调用列表

c# - 从 Access 数据库读取字段时出现 IndexOutOfRangeException

c# - 二进制流 'NN' 不包含有效的 BinaryHeader

wpf - 我的 WPF 应用程序中的复选框宽度在 XP 和 Win7 之间为何不同?

c# - 在键/鼠标事件后禁用 OxyPlot PlotView 最大/最小值

c# - 自定义控件不会在 Visual Studio 设计器中更新

c# - 在后面的代码中多次绑定(bind)到 TextBlock - 我在哪里弄错了?

wpf - 更改 FlowDirection 时镜像复选框勾选

c# - 如何更改 OxyPlot Y 轴字符串格式?

wpf - 刷新 OxyPlot 图表