示例#1
0
        private bool TryFillViewServiceImplementation(FrameworkElement element, ViewServiceRequestEventArgs e)
        {
            ViewServiceCollection viewServices = element.GetValue(
                Interaction.ViewServicesProperty) as ViewServiceCollection;

            if (viewServices == null)
            {
                return(false);
            }

            // Try to find the view service within the host control
            foreach (object actViewService in viewServices)
            {
                if (actViewService == null)
                {
                    continue;
                }

                Type actViewServiceType = actViewService.GetType();
                if (e.RequestedType.GetTypeInfo().IsAssignableFrom(actViewServiceType.GetTypeInfo()))
                {
                    e.Implementation = actViewService;
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        public static ViewServiceCollection GetViewServices(DependencyObject obj)
        {
            FrameworkElement hostElement = obj as FrameworkElement;

            hostElement.EnsureNotNull(nameof(hostElement));

            ViewServiceCollection triggerCollection = (ViewServiceCollection)obj.GetValue(Interaction.ViewServicesProperty);

            if (triggerCollection == null)
            {
                triggerCollection = new ViewServiceCollection(hostElement);
                obj.SetValue(Interaction.ViewServicesProperty, triggerCollection);
            }
            return(triggerCollection);
        }