Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing ChartControl.Properties by code throws exception

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Changing ChartControl.Properties by code throws exception

    Hello,

    When I use this code to modify the properties of the chartcontrol I get a directx exception, which freezes the application and I have to kill the process to exit.

    Code:
    private void setChartControlProperties()
            {
                if (this.ChartControl != null && this.ChartControl.Dispatcher != null )
                {
                    this.ChartControl.Dispatcher.InvokeAsync(new Action(() =>
                    {
                      this.ChartControl.Properties.ChartBackground = new SolidColorBrush(myconfig.ChartControlBackground.Value);
                      this.ChartControl.Properties.AxisPen = new Stroke(new SolidColorBrush(myconfig.ChartControlAxisColor.Value), ConvertDashStyle(myconfig.ChartControlAxisDashStyle), myconfig.ChartControlAxisWidth);
                      this.ChartControl.Properties.GridLineHPen = new GridLine(new Stroke(new SolidColorBrush(myconfig.ChartControlGridHorizontalColor.Value), ConvertDashStyle(myconfig.ChartControlGridHorizontalDashStyle), myconfig.ChartControlGridHorizontalWidth), myconfig.ChartControlGridHorizontalEnabled);
                      this.ChartControl.Properties.GridLineVPen = new GridLine(new Stroke(new SolidColorBrush(myconfig.ChartControlGridVerticalColor.Value), ConvertDashStyle(myconfig.ChartControlGridVerticalDashStyle), myconfig.ChartControlGridVerticalWidth), myconfig.ChartControlGridVerticalEnabled);
    
                      this.ForceRefresh();
                    }));
                }
            }

    The exception message is:
    Code:
    ************** Exception Text **************
    SharpDX.SharpDXException: HRESULT: [0x88990001], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_WRONG_STATE/WrongState], Message: Unknown
       at SharpDX.Result.CheckError()
       at SharpDX.Direct2D1.WindowRenderTarget.Resize(Size2 ixelSizeRef)
       at NinjaTrader.Gui.Chart.Direct2DForm.OnResize(EventArgs e)
       at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
       at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
       at System.Windows.Forms.Control.UpdateBounds()
       at System.Windows.Forms.Control.WmWindowPosChanged(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at NinjaTrader.Gui.Chart.Direct2DForm.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    Is there any way to modify the chartcontrol.Properties by code ?

    Thanks very much.

    #2
    Already solved. I had to freeze the brush.

    Sorry for the inconviences

    Regards


    Code:
    TriggerCustomEvent(o =>
                {
                    Brush b = new SolidColorBrush(myconfig.ChartControlBackground.Value);
                    b.Freeze();
                    chartProperties.ChartBackground = b;
                }, 0, null);

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by usazencort, Today, 01:16 AM
    0 responses
    1 view
    0 likes
    Last Post usazencort  
    Started by kaywai, 09-01-2023, 08:44 PM
    5 responses
    603 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by xiinteractive, 04-09-2024, 08:08 AM
    6 responses
    22 views
    0 likes
    Last Post xiinteractive  
    Started by Pattontje, Yesterday, 02:10 PM
    2 responses
    21 views
    0 likes
    Last Post Pattontje  
    Started by flybuzz, 04-21-2024, 04:07 PM
    17 responses
    230 views
    0 likes
    Last Post TradingLoss  
    Working...
    X