private void AddKeys(OnScreenKeyboardSectionViewModel section, int keysPerRow)
 {
     foreach (var row in section.Rows)
     {
         for (var x = 1; x <= keysPerRow; x++)
         {
             //row.Keys.Add(new ModifierKey(VirtualKeyCode.SHIFT, VirtualKeyCode.LSHIFT, VirtualKeyCode.RSHIFT));
             //row.Keys.Add(new ShiftSensitiveKey(VirtualKeyCode.VK_A, "a", "A"));
         }
         row.Keys[1].ButtonWidth = new GridLength(5, GridUnitType.Star);
     }
 }
        private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            if (_viewModel != null)
            {
                _viewModel.Rows.CollectionChanged -= OnRowsCollectionChanged;
                _viewModel = null;
                OnRowsCollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }

            if (DataContext is OnScreenKeyboardSectionViewModel)
            {
                _viewModel = DataContext as OnScreenKeyboardSectionViewModel;
                _viewModel.Rows.CollectionChanged += OnRowsCollectionChanged;
                OnRowsCollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
        /// <summary>
        /// Build the keyboard layout based on the given class that represents the KPD file given in the constructor.
        /// </summary>
        /// <param name="keyboardLayout">The keyboard layout.</param>
        public void BuildKeyboardLayout(KeyboardLayout keyboardLayout)
        {
            //var sb = new StringBuilder();

            //sb.AppendLine("---------");
            //sb.AppendLine("CharModifiers");
            //sb.AppendLine("---------");
            //foreach (var charModifier in keyboardLayout.CharModifiers)
            //{
            //    sb.AppendLine(string.Format("ModifierBits:{0}:VirtualKey:{1}", charModifier.ModifierBits,
            //        charModifier.VirtualKey));
            //}

            //sb.AppendLine("---------");
            //sb.AppendLine("ScanCodeText");
            //sb.AppendLine("---------");
            //foreach (var scanCodeText in keyboardLayout.CodeText)
            //{
            //    sb.AppendLine(string.Format("ScanCode:{0:X}:Text:{1}", scanCodeText.ScanCode,
            //        scanCodeText.Text));
            //}

            //sb.AppendLine("---------");
            //sb.AppendLine("ScanCodes");
            //sb.AppendLine("---------");
            //foreach (var scanCode in keyboardLayout.ScanCodes.Where(x => !x.E0Set && !x.E1Set))
            //{
            //    sb.AppendLine(string.Format("ScanCode:{0:X}:VirtualKey:{1}:E0:{2}:E1:{3}", scanCode.Code,
            //        scanCode.VirtualKey, scanCode.E0Set, scanCode.E1Set));
            //}

            //sb.AppendLine("---------");
            //sb.AppendLine("ScanCodes E0");
            //sb.AppendLine("---------");
            //foreach (var scanCode in keyboardLayout.ScanCodes.Where(x => x.E0Set))
            //{
            //    sb.AppendLine(string.Format("ScanCode:{0:X}:VirtualKey:{1}:E0:{2}:E1:{3}", scanCode.Code,
            //        scanCode.VirtualKey, scanCode.E0Set, scanCode.E1Set));
            //}

            //sb.AppendLine("---------");
            //sb.AppendLine("ScanCodes E1");
            //sb.AppendLine("---------");
            //foreach (var scanCode in keyboardLayout.ScanCodes.Where(x => x.E1Set))
            //{
            //    sb.AppendLine(string.Format("ScanCode:{0:X}:VirtualKey:{1}:E0:{2}:E1:{3}", scanCode.Code,
            //        scanCode.VirtualKey, scanCode.E0Set, scanCode.E1Set));
            //}

            //sb.AppendLine("---------");
            //sb.AppendLine("VirtualKeys");
            //sb.AppendLine("---------");
            //foreach (var virtualkey in keyboardLayout.VirtualKeys)
            //{
            //    sb.AppendLine(string.Format("VirtualKey:{0}:Attributes:{1}:Characters:{2}", virtualkey.Key,
            //        virtualkey.Attributes, string.Join(" - ", virtualkey.Characters.Select(x => string.Format("{0:X}", x)))));
            //}

            //var result = sb.ToString();

            var mainSection = new OnScreenKeyboardSectionViewModel();
            mainSection.Rows.Add(BuildRow1(keyboardLayout));
            mainSection.Rows.Add(BuildRow2(keyboardLayout));
            mainSection.Rows.Add(BuildRow3(keyboardLayout));
            mainSection.Rows.Add(BuildRow4(keyboardLayout));
            mainSection.Rows.Add(BuildRow5(keyboardLayout));
            Sections.Add(mainSection);
        }