Home
Options

Getting Util.SelectedOutputPanelIndex after calling PanelManager.DisplayControl

Is it possible to accurately get the panel index after creating a new panel via PanelManager.DisplayControl ?

I am using a hyperlink to display a chart in another panel and afterwards I would like to change the hyperlink to just switch to the appropriate panel.

Sometimes Util.SelectedOutputPanelIndex returns the new panel number and my updated hyperlink then works, but sometimes Util.SelectedOutputPanelIndex returns 0.

The following is a simple example showing what I am trying to do.

void Main()
{
    (from r in Enumerable.Range(10, 10) select new { r, Link =  new Hyperlinq(() => DisplayChart(r) , "Display Chart")   }).Dump();
}

object DisplayChart(int r)
{
    var chart = Enumerable.Range(0, r)
        .Chart(x => x.ToString())
        .AddYSeries(y => y, LINQPad.Util.SeriesType.Line, "")
        .ToWindowsChart();

    var op = PanelManager.DisplayControl(chart, $"Chart {r}" ) ;

    var pi = Util.SelectedOutputPanelIndex;

    if (pi == 0)
        throw new Exception("Util.SelectedOutputPanelIndex is zero");

    return new Hyperlinq(() => Util.SelectedOutputPanelIndex = pi , "Display Chart"); 
}

If you run this and click on several of the links to display the charts, some may work, but some may throw the exception.

Comments

  • Options

    Please ignore this.

    I can use PanelManager.GetOutputPanels().Count();

    There is also a bug in my sample as I should have been using Util.OnDemand for the first Hyperlink.

    The following seems to work

    void Main()
    {
        (from r in Enumerable.Range(10, 10) select new { r, Link = Util.OnDemand("Display chart", () => DisplayChart(r)) }).Dump();
    }
    
    object DisplayChart(int r)
    {
        var chart = Enumerable.Range(0, r)
            .Chart(x => x.ToString())
            .AddYSeries(y => y, LINQPad.Util.SeriesType.Line, "")
            .ToWindowsChart();
    
        var op = PanelManager.DisplayControl(chart, $"Chart {r}");
    
        var pi = PanelManager.GetOutputPanels().Count();
    
        return new Hyperlinq(() => Util.SelectedOutputPanelIndex = pi, "Display Chart");
    }
    
Sign In or Register to comment.