Skip to content

Manually created PlotView does not appear #1923

Closed
@lukaszksoll

Description

@lukaszksoll

Hi! I have a problem after OxyPlot update from 2.0.0 to 2.1.0. Currently I cannot display a manually created (in code-behind) PlotView within the tooltip of the canvas. I tried to reproduce it on simpler example and it seems to behave the same.

In the following example tooltip is always empty. It contains proper size control, but there is no chart on the view. Within the comments you can find some code that works, but without tooltip.

When I'm trying to do this implementing PlotView in xaml code via VM - it works.

MainWindow.xaml.cs:

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var plotModel = new PlotModel
            {
                Title = "Long axis titles (clipped at 100%)",
                Series = { new FunctionSeries(Math.Cos, 0, 10, 400) },
            };
            var plotView = new PlotView
            {
                Model = plotModel,
                Width = 400,
                Height = 400,
            };

            var tooltip = new ToolTip { Content = plotView };

            // It works
            //var grid = new Grid()
            //{
            //    Children = { plotView }
            //};
            //Main.Content = grid;

            // It doesn't work
            var grid = new Grid
            {
                Width = 400,
                Height = 500,
                Background = Brushes.Red,
                ToolTip = tooltip,
            };

            grid.ToolTipOpening += (s, args) => plotView.InvalidatePlot();
            Main.Content = grid;


            plotView.InvalidatePlot();
        }
    }

MainWindow.xaml:

<Window x:Class="WpfApp1.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:local="clr-namespace:WpfApp1"
       mc:Ignorable="d"
       Title="MainWindow" Height="450" Width="800" x:Name="Main">

</Window>

Platform:
.NET version: 4.8/6.0
Oxyplot version: 2.1.0

Thank you for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions