【问题标题】:Is there a way to plot OXYplot graph in custom area in WPF window?有没有办法在 WPF 窗口的自定义区域中绘制 OXYplot 图形?
【发布时间】:2020-02-12 10:59:18
【问题描述】:

我想使用 OXYplot 库将多个图形放在一个 WPF 窗口中,因此会有一些 WPF 组件(如按钮)和一些带有图形的矩形。有办法吗?在所有示例中,OXYplot 图占据了整个 WPF 窗口。

我尝试将它放在这样的矩形内,但收到错误“'矩形'类型不支持直接内容”

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="932,547,0,0" Stroke="Black" VerticalAlignment="Top" Width="100">
   <oxy:PlotView Model="{Binding Model}"/>
</Rectangle>

【问题讨论】:

标签: c# wpf visual-studio-2019 oxyplot


【解决方案1】:

将它放在Panel 中或用Border 装饰它:

<Border Background="Yellow" BorderBrush="Black" BorderThickness="1" Padding="10">
    <oxy:PlotView Model="{Binding Model}"/>
</Border>

PlotView 只是一个自定义的Control,您可以在布局中使用它,就像在 WPF 中使用任何其他控件一样。

【讨论】:

    【解决方案2】:

    为简单起见,您也可以使用 Grid 将多个 PlotView 和按钮排列成所需的布局。

    <Grid Margin="10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid Grid.Column="0" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel1}"/>
                <Button Grid.Column="1" Content="Click"/>
            </Grid>
            <Grid Grid.Column="1" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel2}"/>
                <Button Grid.Column="1" Content="Click"/>
            </Grid>
            <Grid Grid.Column="1" Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel3}"/>
                <Button Grid.Column="1" Content="Click"/>
            </Grid>
            <Grid Grid.Column="0" Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <oxy:PlotView Height="500" Width="500" Model="{Binding GraphModel4}"/>
                <Button Grid.Column="1" Content="Click"/>
            </Grid>
        </Grid>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多