Exemplo n.º 1
0
        private object FindComponent(string name)
        {
            if (DesignMode)
            {
                var container = Site.Container;
                if (container == null)
                {
                    return(null);
                }
                for (int i = 0; i < container.Components.Count; i++)
                {
                    var cmp = container.Components[i];
                    if (WinFormsToolkitExtensions.TryGetValue(cmp, "Name") == name)
                    {
                        return(cmp);
                    }
                }
                return(null);
            }
            var containerControl = ContainerControl;

            if (containerControl == null || containerControl.Name == name)
            {
                return(containerControl);
            }
            var field = _containerControlType.GetFieldEx(name, MemberFlags.Public | MemberFlags.NonPublic | MemberFlags.Instance);

            if (field == null)
            {
                return(BindingServiceProvider.VisualTreeManager.FindByName(containerControl, name));
            }
            return(field.GetValueEx <object>(containerControl));
        }
Exemplo n.º 2
0
 private bool AddCompleteItem(IComponent result, out string name, out Type type)
 {
     type = null;
     name = null;
     try
     {
         if (result is Binder)
         {
             return(false);
         }
         name = WinFormsToolkitExtensions.GetComponentName(result);
         if (string.IsNullOrWhiteSpace(name))
         {
             return(false);
         }
         type = result.GetType();
         SortedDictionary <string, AutoCompleteItem> completeItems;
         if (!_controlsDictionary.TryGetValue(name, out completeItems))
         {
             completeItems             = new SortedDictionary <string, AutoCompleteItem>(StringComparer.CurrentCulture);
             _controlsDictionary[name] = completeItems;
         }
         AddCompleteItems(type, completeItems);
         _controlsCompleteItems.Add(new AutoCompleteItem($"{name} ({type.Name})", name));
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
 protected WinFormsBootstrapperBase(bool autoRunApplication = true, PlatformInfo platform = null, bool isDesignMode = false)
     : base(isDesignMode)
 {
     Platform                     = platform ?? WinFormsToolkitExtensions.GetPlatformInfo();
     AutoRunApplication           = autoRunApplication;
     ShutdownOnMainViewModelClose = true;
 }
Exemplo n.º 4
0
        private static object FindByNameControlMember(IBindingMemberInfo bindingMemberInfo, Control control, object[] arg3)
        {
            var root = WinFormsToolkitExtensions.GetRootControl(control);

            if (root != null)
            {
                control = root;
            }
            return(control.Controls.Find((string)arg3[0], true).FirstOrDefault());
        }
        protected sealed override void SetErrors(object target, IList <object> errors, IDataContext context)
        {
            var control = target as Control;

            if (control == null)
            {
                return;
            }
            Control rootControl = WinFormsToolkitExtensions.GetRootControl(control);

            if (rootControl == null)
            {
                return;
            }
            ErrorProvider errorProvider = GetErrorProviderInternal(rootControl);

            if (errorProvider == null)
            {
                return;
            }

            var oldProvider = ToolkitServiceProvider
                              .AttachedValueProvider
                              .GetValue <ErrorProvider>(target, ErrorProviderName, false);

            if (!ReferenceEquals(oldProvider, errorProvider))
            {
                if (oldProvider != null)
                {
                    oldProvider.SetError(control, null);
                    TryDispose(oldProvider);
                }
                ToolkitServiceProvider.AttachedValueProvider.SetValue(control, ErrorProviderName, errorProvider);
                if (errorProvider.Tag == null)
                {
                    errorProvider.Tag = 1;
                }
                else if (errorProvider.Tag is int)
                {
                    errorProvider.Tag = (int)errorProvider.Tag + 1;
                }
            }
            SetErrors(control, errorProvider, errors, context);
        }
Exemplo n.º 6
0
        private static string GetDisplayName(object instance, string name, Type type)
        {
            string text = instance == null ? null : WinFormsToolkitExtensions.TryGetValue(instance, "Text");

            return($"{name} ({type.Name}{(string.IsNullOrEmpty(text) ? "" : ", " + text)})");
        }