Esempio n. 1
0
        private void RelativeSourceOption(FrameworkElement frameworkElement)
        {
            switch (RelativeSource?.Mode)
            {
            case RelativeSourceMode.PreviousData:
                throw new NotImplementedException();

            case RelativeSourceMode.TemplatedParent:
                this._dataContext = frameworkElement?.TemplatedParent;
                break;

            case RelativeSourceMode.Self:
                if (CommandName.Split('.').First() == "Parent")
                {
                    CommandName = String.Join(".", CommandName.Split('.').Skip(1));

                    this._dataContext = frameworkElement?.Parent;
                }
                else
                {
                    this._dataContext = frameworkElement;
                }
                break;

            case RelativeSourceMode.FindAncestor:
                Type type = RelativeSource.AncestorType;

                MethodInfo method = typeof(ExtensionMethod).GetMethod("FindAncestor");


                Object parent = frameworkElement;

                for (int i = 0; i < RelativeSource.AncestorLevel; i++)
                {
                    parent = method.MakeGenericMethod(type)
                             .Invoke(null, new object[] { parent, null });
                }

                this._dataContext = parent;
                break;
            }
        }
 public TaskCommand(string s)
 {
     DisplayName = s;
     if (s.Contains(":"))
     {
         var parts = s.Split(new[] { ':' }, 2);
         CommandName  = parts[0];
         CommandValue = parts[1];
         DisplayName  = CommandName;
     }
     else
     {
         CommandName = s;
     }
     if (CommandName.Contains("="))
     {
         var parts = CommandName.Split(new[] { '=' }, 2);
         DisplayName = parts[0];
         CommandName = parts[1];
     }
 }