Beispiel #1
0
 public void OnItemsAction(IRibbonControl control, string id, int index)
 {
     try
     {
         var boundCollections = FindBoundControls(control.Id, control.GetHwnd(), RibbonBindingType.GalleryItemsSource);
         foreach (var boundCollectionControl in boundCollections)
         {
             if (boundCollectionControl.Binding.Value is System.Collections.IList list)
             {
                 if (index < list.Count)
                 {
                     var commandParameter = list[index];
                     var boundCommands    = FindBoundControls(control.Id, control.GetHwnd(), RibbonBindingType.Command, boundCollectionControl.Binding.SourceObject);
                     var boundCommand     = boundCommands.FirstOrDefault();
                     if (boundCommand != null)
                     {
                         if (boundCommand.Binding.Value is ICommand command)
                         {
                             command?.Execute(commandParameter);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
Beispiel #2
0
        private List <BoundControl> GetBoundItems(IRibbonControl control, int index, RibbonBindingType bindingType)
        {
            List <BoundControl> items = new List <BoundControl>();

            try
            {
                object itemToFind = null;
                var    boundLists = FindBoundControls(control.Id, control.GetHwnd(), RibbonBindingType.GalleryItemsSource);
                foreach (var boundList in boundLists)
                {
                    if (boundList.Binding.Value is System.Collections.IList list)
                    {
                        itemToFind = list[index];
                    }
                }
                if (itemToFind != null)
                {
                    foreach (var item in boundVMControls)
                    {
                        if (item.Binding.SourceObject == itemToFind && item.BindingInfo.RibbonBindingType == bindingType)
                        {
                            items.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(items);
        }
Beispiel #3
0
 public void OnAction(IRibbonControl control)
 {
     try
     {
         var ctrls = FindBoundControls(control.Id, control.GetHwnd(), RibbonBindingType.Command);
         foreach (var ctrl in ctrls)
         {
             if (ctrl.Binding.Value is ICommand command)
             {
                 command.Execute(null);
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
Beispiel #4
0
 private bool GetBoolBinding(IRibbonControl control, RibbonBindingType bindingType)
 {
     try
     {
         var ctrls = FindBoundControls(control.Id, control.GetHwnd(), bindingType);
         foreach (var ctrl in ctrls)
         {
             if (ctrl.Binding.Value is bool boolvalue)
             {
                 return(boolvalue);
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
     return(false);
 }
Beispiel #5
0
        public int GetItemCount(IRibbonControl control)
        {
            try
            {
                var boundItemsSources = FindBoundControls(control.Id, control.GetHwnd(), RibbonBindingType.GalleryItemsSource);

                foreach (var boundItemsSource in boundItemsSources)
                {
                    if (boundItemsSource.Binding.Value is System.Collections.IList items)
                    {
                        return(items.Count);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(0);
        }
Beispiel #6
0
        public void OnActionToggle(IRibbonControl control, bool pressed)
        {
            try
            {
                OnAction(control);

                var toggles = FindBoundControls(control.Id, control.GetHwnd(), RibbonBindingType.TogglePressed);
                foreach (var toggle in toggles)
                {
                    if (toggle.Binding.Value is bool)//TODO: Remove this Workaround for setting a Value to a Binding which sourceObject don't have this Property.
                    {
                        toggle.Binding.Value = pressed;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }