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 Belfortbucks, Today, 09:29 PM
    0 responses
    3 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Working...
    X