Oxyplot(wpf)去掉PlotView右边的空space

Oxyplot (wpf) get rid of empty space to the right of PlotView

我正在为 WPF 使用 OxyPlot,PlotView 在它的右侧添加了一个 space,而不是像您在这张图片中看到的那样填满整个区域:

我添加了黑框以显示 PlotView 应该延伸到的位置。

但在设计器中,PlotView 确实延伸了这么远:

这是可以修复的吗?或者解决它的唯一方法是“作弊”,而不是将控件放在面板中,我只是将右侧重叠在 PlotView 上。

<Grid Background="{StaticResource Milky}">
    <DockPanel>
        <Grid Height="50" Width="5" DockPanel.Dock="Left"/>
        <Grid Height="5" Width="50" DockPanel.Dock="Top"/>
        <Grid Width="122" DockPanel.Dock="Right" VerticalAlignment="Top">
            <StackPanel>
                <Border Margin="3" Height="248" Width="116" BorderThickness="1" BorderBrush="{StaticResource LightGrayGray}" CornerRadius="3">
                    <ItemsControl ItemsSource="{Binding Path=GraphLineItems}" HorizontalAlignment="Left">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <local:GraphLineItemV DataContext="{Binding }" ColorPalette="{StaticResource MilkyPalette}">
                                </local:GraphLineItemV>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Border>
                <Border Margin="3 0 3 3" Height="128" BorderThickness="1" BorderBrush="{StaticResource LightGrayGray}" CornerRadius="3">
                    <WrapPanel>
                        <local:IconButton Width="32" Command="{Binding Path=FitToFrameCmd}" ToolTip="{StaticResource ToolTipFitGraph}" Margin="1" Height="32" BorderThickness="1" IconHeight="28" IconWidth="28" ColorPaletteFore="{StaticResource DarkestGraySolid}" ColorPalette="{StaticResource MilkyGPalette}" Image="{StaticResource ZoomIcon}" IconMargin="1"/>
                        <local:IconButton Width="32" Command="{Binding Path=ClearGraphCmd}" ToolTip="{StaticResource ToolTipClearGraph}" Margin="1" Height="32" BorderThickness="1" IconHeight="24" IconWidth="24" ColorPaletteFore="{StaticResource DarkestGraySolid}" ColorPalette="{StaticResource MilkyGPalette}" Image="{StaticResource DeleteIcon}" IconMargin="4"/>
                    </WrapPanel>
                </Border>
            </StackPanel>
        </Grid>

        <Grid Height="80" DockPanel.Dock="Bottom">
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                <local:ColoredImage x:Name="zoomIcon" Image="{StaticResource ZoomIcon}" Width="24" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" Color="{StaticResource Gray}"/>
                    <Slider HorizontalAlignment="Left" Minimum="0.5" Maximum="85" VerticalAlignment="Top" Margin="0,5,0,0" Value="{Binding Zoom, UpdateSourceTrigger=PropertyChanged}">
                        <Slider.Width>
                            <MultiBinding Converter="{StaticResource Subtraction}">
                                <Binding Path="ActualWidth" ElementName="graph"/>
                                <Binding Path="ActualWidth" ElementName="zoomIcon"/>
                            </MultiBinding>
                        </Slider.Width>
                    </Slider>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
                    <TextBlock Text="Refresh rate:  " HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    <TextBox Text="{Binding UpdateInterval, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" PreviewTextInput="NumberValidationTextBox" MaxLength="3" FontFamily="{StaticResource MonoFont}" Width="28" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    <TextBlock Text=" (ms)" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
                    <TextBlock Text="Saved length: " HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    <TextBox Text="{Binding SavedLength, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" PreviewTextInput="NumberValidationTextBox" MaxLength="3" FontFamily="{StaticResource MonoFont}" Width="28" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    <TextBlock Text=" (s)" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </StackPanel>
            </StackPanel>
        </Grid>
        <Grid x:Name="grid">
            <Canvas x:Name="canvas" Background="{StaticResource White}"/>
            <Grid Background="Black" Width="20" Height="20" HorizontalAlignment="Right"/>
            <oxy:PlotView x:Name="graph" Background="Transparent"/>
        </Grid>
    </DockPanel>
</Grid>

我猜你将 PlotView 绑定到 PlotModel?在这种情况下,您可以设置 PlotModel 的 PlotMargins 属性 来设置绘图视图中绘图区域的边距,并独立地为所有四个边分配值。

为了完全去掉右边的边距,需要赋负值。

我使用这条线创建了下面的图

plotModel.PlotMargins = new OxyThickness(40, -8, -8, 35);

我更改了绘图视图的一般背景颜色,使其更清晰。