Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Can I change background of GridArea in procedural code?
posted

I can  change background of GridArea using XAML

        <igChart:XamWebChart x:Name="chart1">
            <igChart:XamWebChart.Scene>
                <igChart:Scene>
                    <igChart:Scene.GridArea>
                        <igChart:GridArea Background="PaleGreen" />
                    </igChart:Scene.GridArea>
                </igChart:Scene>
            </igChart:XamWebChart.Scene>
        </igChart:XamWebChart>

In procedural code,

    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Page_Loaded);
        }
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            chart1 = new XamWebChart();
            
            Series s1 = new Series();
            s1.ChartType = ChartType.Column;
            
            DataPoint d = new DataPoint();
            d.Label = "point1";
            d.Value = 10;
            DataPoint d1 = new DataPoint();
            d1.Value = 20;
            d1.Label = "point2";
            DataPoint d2 = new DataPoint();
            d2.Value = 30;
            d2.Label = "point3";
            
            s1.DataPoints.Add(d);
            s1.DataPoints.Add(d1);
            s1.DataPoints.Add(d2);
            this.chart1.Series.Add(s1);
            this.chart1.Scene.GridArea.Background = new SolidColorBrush(Colors.Green);
            this.LayoutRoot.Children.Add(chart1);
            
        }
        
        private XamWebChart chart1;
    }
Can Rebuild succeeded,But Run 
Row: 53 
Error: Unhandled Error in Silverlight 2 Application 
Code: 4004 
Category: ManagedRuntimeError 
Message: System.NullReferenceException: Object reference not set to instance of object. 
    At ChartByCode.Page.Page_Loaded (Object sender, RoutedEventArgs e) 
    At System.Windows.CoreInvokeHandler.InvokeEventHandler (Int32 typeIndex, Delegate 
handlerDelegate, Object sender, Object args) 
    At MS.Internal.JoltHelper.FireEvent (IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 
argsTypeIndex, String eventName)

 

 

 

Parents
  • 28496
    Suggested Answer
    Offline posted

    this should work better:

    this.chart1.Scene = new Scene();
    this.chart1.Scene.GridArea = new GridArea();
    this.chart1.Scene.GridArea.Background = new SolidColorBrush(Colors.Green);
               
    this.LayoutRoot.Children.Add(chart1);

    this.chart1.Refresh();

Reply Children
No Data