/// <summary>
        /// A new Marker associated with a counter control has been created;
        /// Increment the counter controls value, and add the metatag to all data structures (including the database)
        /// </summary>
        /// <param name="myCounter"></param>
        /// <param name="mtag"></param>
        private void Markers_NewMetaTag(MyCounter myCounter, MetaTag mtag)
        {
            // Get the Counter Control's contents,  increment its value (as we have added a new marker)
            // Then update the control's content as well as the database
            string counter_data = myCounter.Content;

            if (String.IsNullOrWhiteSpace(counter_data)) counter_data = "0";
            int count = 0;
            try {
                count = Convert.ToInt32(counter_data);
            }
            catch
            {
                count = 0; // If we can't convert it, assume that someone set the default value to a non-integer in the template, and just revert it to zero.
            }
            count++;
            counter_data = count.ToString();
            this.state.isContentValueChangedFromOutside = true;
            dbData.UpdateRow(dbData.CurrentId, myCounter.DataLabel, counter_data);
            myCounter.Content = counter_data;
            state.isContentValueChangedFromOutside = false;

            // Find the metatagCounter associated with this particular control so we can add a metatag to it
            MetaTagCounter metatagCounter = null;
            foreach (MetaTagCounter mtcounter in this.CounterCoords)
            {
                if (mtcounter.DataLabel == myCounter.Key)
                {
                    metatagCounter = mtcounter;
                    break;
                }
            }

            // Fill in the metatag information. Also create a TagFinder (which contains a reference to the counter index) and add it as the object's metatag
            mtag.Label = myCounter.Label;   // The tooltip will be the counter label plus its data label
            mtag.Label += "\n" + myCounter.DataLabel;
            mtag.Brush = Brushes.Red;               // Make it Red (for now)
            mtag.DataLabel = myCounter.DataLabel;
            mtag.Annotate = true; // Show the annotation as its created. We will clear it on the next refresh
            mtag.AnnotationAlreadyShown = false;

            // Add the meta tag to the metatag counter
            metatagCounter.AddMetaTag(mtag);

            // Update this counter's list of points in the marker atabase
            String pointlist = "";
            foreach (MetaTag mt in metatagCounter.MetaTags)
            {
                if (! pointlist.Equals ("") ) pointlist += Constants.MARKERBAR; // We don't put a marker bar at the beginning of the point list
                pointlist += String.Format("{0:0.000},{1:0.000}", mt.Point.X, mt.Point.Y); // Add a point in the form x,y e.g., 0.5, 0.7
            }
            this.dbData.MarkerTableAddPoint(myCounter.DataLabel, pointlist);
            RefreshTheMarkableCanvasListOfMetaTags(true);
            Speak(myCounter.Content + " " + myCounter.Label); // Speak the current count
        }
        public void GenerateControls(DBData dbData)
        {
            const string EXAMPLE_DATE = "28-Dec-2014";
            const string EXAMPLE_TIME = "04:00 PM";

            string key = ""; // Construct a key

            Propagate = new Propagate(dbData);
            //this.ControlGrid.Inlines.Clear();
            //this.WP.Children.Clear();

            DataTable sortedTemplateTable = dbData.TemplateGetSortedByControls();
            for (int i = 0; i < sortedTemplateTable.Rows.Count; i++)
            {
                // Get the values for each control
                DataRow row = sortedTemplateTable.Rows[i];
                string type = row[Constants.TYPE].ToString();
                string defaultValue = row[Constants.DEFAULT].ToString();
                string label = row[Constants.LABEL].ToString();
                string tooltip = row[Constants.TOOLTIP].ToString();
                string width = row[Constants.TXTBOXWIDTH].ToString();
                int    iwidth = (width == "") ? 0 : Convert.ToInt32(width);
                string visiblity = row[Constants.VISIBLE].ToString();
                bool   bvisiblity = ("true" == visiblity.ToLower ()) ? true : false;
                string copyable = row[Constants.COPYABLE].ToString();
                bool   bcopyable = ("true" == copyable.ToLower ()) ? true : false;
                string list = row[Constants.LIST].ToString();
                int id = Convert.ToInt32 (row[Constants.ID].ToString ()); // TODO Need to use this ID to pass between controls and data

                // Get the key
                key = (string) row[Constants.DATALABEL];
                if (type == Constants.DATE && defaultValue == "")
                {
                    defaultValue = EXAMPLE_DATE;
                }
                else if (type == Constants.TIME && defaultValue == "")
                {
                    defaultValue = EXAMPLE_TIME;
                }

                if (type == Constants.FILE || type == Constants.FOLDER || type == Constants.DATE || type == Constants.TIME || type == Constants.NOTE)
                {
                    bool createContextMenu = (type == Constants.FILE) ? false : true;
                    MyNote myNote = new MyNote(this, createContextMenu);
                    myNote.Key = key;
                    myNote.Label = label;
                    myNote.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myNote.Tooltip = tooltip;
                    myNote.Width = iwidth;
                    myNote.Visible = bvisiblity;
                    myNote.Content = defaultValue;
                    myNote.ReadOnly = (type == Constants.FOLDER || type == Constants.FILE) ? true : false; // File and Folder Notes are read only i.e., non-editable by the user
                    myNote.Copyable = bcopyable;
                    this.ControlGrid.Inlines.Add(myNote.Container);
                    //this.WP.Children.Add(myNote.Container);
                    this.ControlFromDataLabel.Add(key, myNote);
                }
                else if (type == Constants.FLAG || type == Constants.DELETEFLAG)
                {
                    MyFlag myFlag = new MyFlag(this, true);
                    myFlag.Key = key;
                    myFlag.Label = label;
                    myFlag.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myFlag.Tooltip = tooltip;
                    myFlag.Width = iwidth;
                    myFlag.Visible = bvisiblity;
                    myFlag.Content = defaultValue;
                    myFlag.ReadOnly = false; // Flags are editable by the user
                    myFlag.Copyable = bcopyable;
                    //this.WP.Children.Add(myFlag.Container);
                    this.ControlGrid.Inlines.Add(myFlag.Container);
                    this.ControlFromDataLabel.Add(key, myFlag);
                }
                else if (type == Constants.COUNTER)
                {
                    MyCounter myCounter = new MyCounter(this, true);
                    myCounter.Key = key;
                    myCounter.Label = label;
                    myCounter.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myCounter.Tooltip = tooltip;
                    myCounter.Width = iwidth;
                    myCounter.Visible = bvisiblity;
                    myCounter.Content = defaultValue;
                    myCounter.ReadOnly = false; // Couonters are editable by the user
                    myCounter.Copyable = bcopyable;
                    this.ControlGrid.Inlines.Add(myCounter.Container);
                    //this.WP.Children.Add(myCounter.Container);
                    this.ControlFromDataLabel.Add(key, myCounter);
                }
                else if (type == Constants.FIXEDCHOICE || type == Constants.IMAGEQUALITY)
                {
                    MyFixedChoice myFixedChoice = new MyFixedChoice(this, true, list);
                    myFixedChoice.Key = key;
                    myFixedChoice.Label = label;
                    myFixedChoice.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myFixedChoice.Tooltip = tooltip;
                    myFixedChoice.Width = iwidth;
                    myFixedChoice.Visible = bvisiblity;
                    myFixedChoice.Content = defaultValue;
                    myFixedChoice.ReadOnly = false; // Fixed choices are editable (by selecting a menu) by the user
                    myFixedChoice.Copyable = bcopyable;
                    this.ControlGrid.Inlines.Add(myFixedChoice.Container);
                    //this.WP.Children.Add(myFixedChoice.Container);
                    this.ControlFromDataLabel.Add(key, myFixedChoice);
                }
            }
            //var panel = this.ButtonLocation.Parent as Panel;
            //panel.Children.Remove(this.ButtonLocation);
            //this.ControlGrid.Inlines.Add(this.ButtonLocation);
        }