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 LeonaJohner, Today, 05:45 AM
    0 responses
    1 view
    0 likes
    Last Post LeonaJohner  
    Started by tossielwovell, Today, 05:31 AM
    0 responses
    1 view
    0 likes
    Last Post tossielwovell  
    Started by gviand, Today, 05:14 AM
    0 responses
    4 views
    0 likes
    Last Post gviand
    by gviand
     
    Started by Rumburak, Today, 04:56 AM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Marco  
    Started by bdc286, Today, 03:38 AM
    2 responses
    11 views
    0 likes
    Last Post bdc286
    by bdc286
     
    Working...
    X