/// <summary>
        /// Generate textboxes for hex representation dynamically based on the user data length
        /// </summary>
        /// <param name="data"> Maximum user memory data received from the module</param>
        private void GenerateControls(byte [] data)
        {
            bool islastHexBytesAddedToHexEdtr = false;

            int datalength = data.Length;
            
            // Create a new label to represent next address eg: 0x0001, 0x0002 etc
            Label lblHexAddressRepEmptySpace = new Label();
            lblHexAddressRepEmptySpace.Height = 30;
            lblHexAddressRepEmptySpace.Width = 57;
            lblHexAddressRepEmptySpace.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            lblHexAddressRepEmptySpace.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            lblHexAddressRepEmptySpace.Content = "";
            stkpnlHexClmnAddress.Children.Add(lblHexAddressRepEmptySpace);
            // Create a name scope for the hex address stackpanel. 
            NameScope.SetNameScope(stkpnlHexClmnAddress, new NameScope());
            for (int i = 0; i < 16; i++)
            {
                // Create a new label to represent next address eg: 0x0001, 0x0002 etc
                Label lblHexAddressRep = new Label();
                lblHexAddressRep.Height = 30;
                lblHexAddressRep.Width = 57;
                lblHexAddressRep.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                lblHexAddressRep.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                lblHexAddressRep.Content = "0x" + (i).ToString("x4"); ;
                stkpnlHexClmnAddress.Children.Add(lblHexAddressRep);
            }

            StackPanel stkPannel = new StackPanel();
            stkPannel.Orientation = Orientation.Horizontal;
            stkPannel.Name = "stkpnlHexAddress0";
            stkPannel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            stkPannel.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            // Cache textboxes which is to be used for editing and writing back to the tag
            txtbxHexRepList = new TextBox[data.Length];
            
            // Create a name scope for the stackpanel. 
            NameScope.SetNameScope(stkPannel, new NameScope());
            
            // Create a label Hex word address eg: 0x0000 and add it to the stack panel
            Label lblHexAddress = new Label();
            lblHexAddress.Content = "0x0000";          
            lblHexAddress.Height = 30;
            lblHexAddress.Width = 57;
            lblHexAddress.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            lblHexAddress.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            stkPannel.Children.Add(lblHexAddress);

            for (int i = 1; i <= data.Length; i++)
            {
                islastHexBytesAddedToHexEdtr = true;
                // Create the textbox to hold the user byte data
                TextBox txtbxhexAddressed = new TextBox();

                CommandBinding txtbxhexAddressedCutCmdBnd = new CommandBinding(ApplicationCommands.Cut);
                txtbxhexAddressedCutCmdBnd.CanExecute += new CanExecuteRoutedEventHandler(txtbxhexAddressedCutCmdBnd_CanExecute);
                txtbxhexAddressedCutCmdBnd.Executed += new ExecutedRoutedEventHandler(txtbxhexAddressedCutCmdBnd_Executed);

                CommandBinding txtbxhexAddressedPasteCmdBnd = new CommandBinding(ApplicationCommands.Paste);
                txtbxhexAddressedPasteCmdBnd.CanExecute += new CanExecuteRoutedEventHandler(txtbxhexAddressedPasteCmdBnd_CanExecute);
                txtbxhexAddressedPasteCmdBnd.Executed += new ExecutedRoutedEventHandler(txtbxhexAddressedPasteCmdBnd_Executed);
                txtbxhexAddressed.CommandBindings.Add(txtbxhexAddressedCutCmdBnd);
                txtbxhexAddressed.CommandBindings.Add(txtbxhexAddressedPasteCmdBnd);

                // register the event
                txtbxhexAddressed.PreviewTextInput +=new TextCompositionEventHandler(this.txtblk0ByteAddressClmn1_PreviewTextInput);
                txtbxhexAddressed.PreviewKeyDown += new KeyEventHandler(this.txtblk0ByteAddressClmn1_PreviewKeyDown);
                txtbxhexAddressed.IsUndoEnabled = false;       
                txtbxhexAddressed.Name = "txtNumber"+i.ToString();
                txtbxhexAddressed.Text = "00";
                txtbxhexAddressed.CaretBrush = Brushes.Black;
                txtbxhexAddressed.Background = (SolidColorBrush)new BrushConverter().ConvertFrom("#0A000000");
                txtbxhexAddressed.TextAlignment = TextAlignment.Center;
                txtbxhexAddressed.Height = 30;
                txtbxhexAddressed.Width = 57;
                txtbxhexAddressed.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                txtbxhexAddressed.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                txtbxhexAddressed.MaxLength = 2;
                txtbxHexRepList[i - 1] = txtbxhexAddressed;   
                        
                if (i % 16 == 0)
                {
                    // 16 bytes on each row

                    // Add 16th byte in the stack panel
                    stkPannel.Children.Add(txtbxhexAddressed);
                    // To get original event handler to work by registering the name and 
                    // This will then allow us to call FindName on the StackPanel and find the TextBox.
                    stkPannel.RegisterName(txtbxhexAddressed.Name, txtbxhexAddressed);

                    // Add the stackpanel with maximum 16 bytes to the parent stackpanel
                    stkpnlByteAddress.Children.Add(stkPannel);

                    // To get original event handler to work by registering the name and 
                    // This will then allow us to call FindName on the parent stackPanel and find the child stackpanel.
                    stkpnlByteAddress.RegisterName(stkPannel.Name, stkPannel);    
                    
                    // Create a new stackpanel to hold next 16 bytes
                    stkPannel = new StackPanel();
                    stkPannel.Orientation = Orientation.Horizontal;
                    stkPannel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    stkPannel.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                    stkPannel.Name = "stkpnlHexAddress" + i.ToString();

                    // Create a new label to represent next address eg: 0x0001, 0x0002 etc
                    lblHexAddress = new Label();
                    lblHexAddress.Height = 30;
                    lblHexAddress.Width = 57;
                    lblHexAddress.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                    lblHexAddress.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    lblHexAddress.Content = "0x"+(i).ToString("x4"); ;
                    stkPannel.Children.Add(lblHexAddress);

                    // Create a name scope for the stackpanel. 
                    NameScope.SetNameScope(stkPannel, new NameScope());
                }
                else
                {
                    stkPannel.Children.Add(txtbxhexAddressed);
                    stkPannel.RegisterName(txtbxhexAddressed.Name, txtbxhexAddressed);
                    islastHexBytesAddedToHexEdtr = false;
                }
            }

            // Will be false when the last set of bytes are not divisible by 16. 
            // Hence add the remaining bytes to the parent stack panel for ex: if the length of the data is 40 bytes and 64 bytes.
            if (!islastHexBytesAddedToHexEdtr)
            {
                // Add the stackpanel with maximum 16 bytes to the parent stackpanel
                stkpnlByteAddress.Children.Add(stkPannel);

                // To get original event handler to work by registering the name and 
                // This will then allow us to call FindName on the parent stackPanel and find the child stackpanel.
                stkpnlByteAddress.RegisterName(stkPannel.Name, stkPannel);    
            }
            hexAddressEdtrScrollViewer.ScrollToTop();
        }