/// <summary>
        /// Pairing accelerator to definitions.
        /// </summary>
        /// <param name="ca"></param>
        private static void AddCustomAcceleratorToDefinition(CustomAccelerator ca)
        {
            AcceleratorDefinition definitionForCa;

            try
            {  //xaml accelerator and accelerators definition is paired by identity
                definitionForCa = AcceleratorsDefinitions.SingleOrDefault(x => x.Identity == ca.Identity);
            }
            catch (InvalidOperationException ex)
            {
                throw new InvalidOperationException($"There is probably multiple definitions of same identity({ca.Identity})", ex);
            }

            if (definitionForCa == null)
            {
                Debug.WriteLine($"There is no definition for accelerator {ca.Identity}");
            }
            else
            {
                var frame = Window.Current.Content as Frame;

                if (frame != null)
                {
                    ca.TypeOfPageOfAccelerator = frame.SourcePageType;
                }
                else
                {
                }
                Debug.WriteLine("ACC [age" + ca.TypeOfPageOfAccelerator.Name);

                definitionForCa.CustomAccelerators.RemoveAll(x => x.TypeOfPageOfAccelerator != ca.TypeOfPageOfAccelerator);
                definitionForCa.CustomAccelerators.Add(ca);
                ca.SetKeyModifierLabel(definitionForCa.Key, definitionForCa.Modifiers, definitionForCa.Label);
            }
        }
Example #2
0
        public static void SetIdentity(Button obj, string value)
        {
            obj.SetValue(IdentityProperty, value);
            CustomAccelerator ca = new CustomAccelerator(obj, value, GetIsEnabled(obj));

            obj.KeyboardAccelerators.Insert(0, ca);
        }
 /// <summary>
 /// this is called when customAcc is constructed in xaml
 /// </summary>
 /// <param name="ca"></param>
 internal static void AddToList(CustomAccelerator ca)
 {
     if (AcceleratorsDefinitions.Count == 0)
     {//when there is no definition (xaml in constructed before accelerators definiton
         //(which is right because it time consuming operation) it will add to hanging accelerator)
         HangingAccelerators.Add(ca);
     }
     else
     {  //for examle accelerator from non-default page is added
         AddCustomAcceleratorToDefinition(ca);
     }
 }