Ejemplo n.º 1
0
        protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
        {
            var dataTemplate = parent as DataTemplate;

            if (dataTemplate == null)
            {
                return(null);
            }
            //var templatedParent = param as FrameworkElement;
            //if (templatedParent == null)
            //	return null;
            var templatedParentFrame = context.GetBacktracedFrame(1);
            var templatedParent      = templatedParentFrame.ResolvedValue as FrameworkElement;

            if (templatedParent == null)
            {
                return(null);
            }
            var targetObject = dataTemplate.FindName(TargetName, templatedParent);

            if (targetObject == null)
            {
                return(null);
            }
            return(targetObject);
        }
Ejemplo n.º 2
0
 //TODO supporting Parameters and parameter selectors
 protected override object ResolveImpl(
     object parent,
     ref SelectorTreeResolutionContext context)
 {
     return(parent
            .Reflect()
            .InvokeMethod <object>(
                MemberDescriptor.Any,
                MethodName));
 }
Ejemplo n.º 3
0
 protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
 {
     if (parent == null)
     {
         //TODO how to handle this?
     }
     if (PropertyName == "Template" || PropertyName == "ContentTemplate")
     {
         (parent as FrameworkElement)?.ApplyTemplate();
     }
     return(parent.GetPropertyValue <object>(PropertyName));
 }
        protected override object ResolveImpl(
            object parent,
            ref SelectorTreeResolutionContext context)
        {
            parent.IsNotNull(nameof(parent));
            var frameworkElement = parent.IsOfType <FrameworkElement>();

            var resolvedParent = frameworkElement
                                 .FindParent(AncestorType, AncestorLevel);

            return(resolvedParent);
        }
Ejemplo n.º 5
0
        protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
        {
            var list = parent as IList;

            if (list == null)
            {
                throw new NotSupportedException($"ArrayElementSelectors not supported on type \'{parent.GetType().Name}\'. " +
                                                $"Object must be convertable to \'IList\'.");
            }
            var element = list[ArrayIndex];

            return(element);
        }
Ejemplo n.º 6
0
        protected override object ResolveImpl(
            object parent,
            ref SelectorTreeResolutionContext context)
        {
            var template = context
                           .RootExecutionContext
                           .Reflect()
                           .GetFieldValue <FrameworkTemplate>(
                MemberDescriptor.Any,
                TemplatePropertyName);

            return(template);
        }
Ejemplo n.º 7
0
        protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
        {
            var listView = context.RootExecutionContext as ListView;

            if (listView == null)
            {
                throw new ReactionExecutionException("Can only execute FindNameInListViewSelector on an ListView.");
            }

            listView.ApplyTemplate();

            var listViewItem = parent as ListViewItem;

            if (listViewItem == null)
            {
                throw new ReactionExecutionException("Parent selector must be a \'ListViewItem\'.");
            }

            listViewItem.ApplyTemplate();

            var currentChild = VisualTreeHelper.GetChild(listViewItem, 0) as ContentPresenter;

            if (currentChild == null)
            {
                throw new ReactionExecutionException(
                          "The root visual child of the ListViewItem must be of Type \'ContentPresenter\'.");
            }

            currentChild.ApplyTemplate();

            //var targetElement = currentChild.FindName(TargetName);
            var targetElement = currentChild.ContentTemplate.FindName(TargetName, currentChild);

            if (targetElement == null)
            {
                throw new ReactionExecutionException(
                          $"The name \'{TargetName}\' could not be found in the ListViewItem's ContentPresenter.");
            }

            var targetAnimatable = targetElement as IAnimatable;

            if (targetAnimatable == null)
            {
                throw new ReactionExecutionException(
                          $"The targeted element with name \'{TargetName}\' must be of type \'IAnimatable\'. " +
                          $"Actual type \'{targetElement.GetType().Name}\' is not supported.");
            }

            return(targetAnimatable);
        }
        protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
        {
            var control = parent as Control;

            if (control == null)
            {
                throw new NotSupportedException("Can only execute FindNameInControlTemplateSelector on a Control.");
            }

            //var frameworkElement = parent as FrameworkElement;
            //if(frameworkElement == null)
            //	throw new NotSupportedException("Parent selector must be FrameworkElement.");

            //frameworkElement.ApplyTemplate();
            control.ApplyTemplate();

            var targetElement = control.Template.FindName(TargetName, control);

            return(targetElement);
        }
Ejemplo n.º 9
0
        protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
        {
            var container = parent as FrameworkElement;

            if (container == null)
            {
                return(null);
            }
            // TODO check if already applied? is this necessary?
            container.ApplyTemplate();
            //TODO trycatch index out of bounds
            var currentChild = VisualTreeHelper.GetChild(container, ChildIndex);

            // as ContentPresenter;
            if (currentChild == null)
            {
                return(null);
            }
            return(currentChild);
        }
        protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
        {
            var itemsControl = context.RootExecutionContext as ItemsControl;

            if (itemsControl == null)
            {
                throw new NotSupportedException("Can only execute FindNameInItemsControlSelector on an ItemsControl.");
            }

            var frameworkElement = parent as FrameworkElement;

            if (frameworkElement == null)
            {
                throw new NotSupportedException("Parent selector must be FrameworkElement.");
            }

            frameworkElement.ApplyTemplate();
            itemsControl.ApplyTemplate();

            var targetElement = itemsControl.ItemTemplate.FindName(TargetName, frameworkElement);

            return(targetElement);
        }
Ejemplo n.º 11
0
 protected override object ResolveImpl(object parent, ref SelectorTreeResolutionContext context)
 {
     return(context.RootExecutionContext);
 }
 protected override object ResolveImpl(
     object parent,
     ref SelectorTreeResolutionContext context)
 {
     return(ParameterValue);
 }