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 Newant, Today, 08:13 AM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by alejandro888, Yesterday, 10:14 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by devro, Yesterday, 07:00 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by mr_trade, Today, 07:13 AM
    0 responses
    16 views
    0 likes
    Last Post mr_trade  
    Started by gchan, Yesterday, 05:48 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Working...
    X