Exemple #1
0
 public MainWindow()
 {
     InitializeComponent();
     this.DataContext  = this;
     this.ColorScheme  = BrushHelper.CreateRainbowBrush(false);
     this.Categories   = new[] { "Asia", "Africa", "North America", "South America", "Antarctica", "Europe", "Australia" };
     this.ColorScheme2 = BrushHelper.CreateSteppedGradientBrush(new[] { Colors.Yellow, Colors.Brown, Colors.Red, Colors.Green, Colors.White, Colors.Orange, Colors.Blue }, false);
 }
        void dg_Variables_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            //dg_Variables.GotFocus += Row_GotFocus;

            DataGrid dg = (DataGrid)sender;

            TextBox tb = e.EditingElement as TextBox;


            Logger.Log(sender, string.Format("Variable affected: {0}, old value: {1}", tb.Text, oldText));

            // if new text != old text -> remove old var
            if (tb.Text != oldText)
            {
                try { RemoveGeometry(oldText); }
                catch (Exception)
                {
                }
            }

            // if empty return and don't add row
            if (string.IsNullOrEmpty(tb.Text))
            {
                e.Cancel = true;
                return;
            }

            // if new var is already in dict exit
            if (_dict.ContainsKey(tb.Text))
            {
                e.Cancel = true;
                return;
            }
            else
            {
                bool added = AddGeometry(tb.Text).Result;

                if (added)
                {
                }
                else
                {
                    e.Row.Background = BrushHelper.CreateRainbowBrush();
                    //e.Cancel = true;
                }
            }
        }