private void ClickWindow(Point point, Canvas canvas)
        {
            count++;
            if (count > 10)
            {
                return;
            }

            Path path = new Path();

            //path.Fill = AttachedProperty.GetFillColor(path);
            path.Stroke  = AttachedProperty.GetFillColor(path);
            path.Opacity = 1 - count * 0.1 >= 0.5 ? 1 - count * 0.1 : 0.5;
            DropShadowEffect dropShadowEffect = new DropShadowEffect();

            dropShadowEffect.BlurRadius  = 10;
            dropShadowEffect.Color       = Colors.LightGray;
            dropShadowEffect.ShadowDepth = 1;
            dropShadowEffect.Direction   = 90;
            path.Effect = dropShadowEffect;
            EllipseGeometry ellipseGeometry = new EllipseGeometry(point, 1 + 3 * count, 1 + 3 * count);

            path.Data = ellipseGeometry;
            canvas.Children.Add(path);
        }
Пример #2
0
        /// <summary>
        ///   Serializes a PropertyPath.
        /// </summary>
        /// <param name = "path">The path being serialized.</param>
        /// <param name = "propertyName">The name of the property being serialized.</param>
        /// <param name = "propNs">The namespace for the property being serialized.</param>
        /// <param name = "writer">The writer being used for serialization.</param>
        /// <param name = "prefixMappings">A mapping of xml namespaces to prefixes.</param>
        /// <param name = "cycleCheckObjects">The set of objects on the stack (for cycle detection).</param>
        protected virtual void VisitPropertyPath(string path,
                                                 string propertyName,
                                                 string propNs,
                                                 XmlWriter writer,
                                                 IDictionary <string, string> prefixMappings,
                                                 ISet <object> cycleCheckObjects)
        {
            string          newPropertyPath = path;
            MatchCollection apMatches       = AttachedPropertyPathRegex.Matches(path);

            foreach (Match m in apMatches)
            {
                string           prefix    = m.Groups["prefix"].Value;
                string           className = m.Groups["className"].Value;
                string           propName  = m.Groups["propName"].Value;
                AttachedProperty ap        = this.FindAttachedProperty(className, propName);
                string           ns        = this.GetNamespace(ap.Getter.DeclaringType, prefixMappings);
                string           xmlPrefix = writer.LookupPrefix(ns);
                if (xmlPrefix == null || !xmlPrefix.Equals(prefix))
                {
                    writer.WriteAttributeString("xmlns", prefix, null, ns);
                }
            }
            if (propNs == null)
            {
                writer.WriteAttributeString(propertyName, newPropertyPath);
            }
            else
            {
                writer.WriteAttributeString(this.GetPrefix(propNs, prefixMappings, writer),
                                            propertyName,
                                            propNs,
                                            newPropertyPath);
            }
        }
        internal void RegisterAttachedProperty <T>(string propertyName, bool isBrowsable, bool isVisibleToModelItem, T defaultValue)
        {
            AttachedProperty <T> attachedProperty = new AttachedProperty <T>
            {
                IsBrowsable          = isBrowsable,
                IsVisibleToModelItem = isVisibleToModelItem,
                Name      = propertyName,
                OwnerType = modelType,
                Getter    = (modelItem) =>
                {
                    T result = (T)viewStateService.RetrieveViewState(modelItem, propertyName);
                    return(result == null ? defaultValue : result);
                },
                Setter = (modelItem, value) =>
                {
                    if (value == null || value.Equals(defaultValue))
                    {
                        viewStateService.StoreViewStateWithUndo(modelItem, propertyName, null);
                    }
                    else
                    {
                        viewStateService.StoreViewStateWithUndo(modelItem, propertyName, value);
                    }
                }
            };

            attachedPropertiesService.AddProperty(attachedProperty);
            attachedProperties.Add(propertyName, attachedProperty);
        }
        public override void GenerateAttachedPropertyDescriptor(AttachedProperty attachedProperty, Source staticMembers)
        {
            string readOnlyParam = attachedProperty.IsReadOnly ? ", readOnly:true" : "";

            staticMembers.AddLine(
                $"public static readonly AttachedUIProperty {PropertyDescriptorName(attachedProperty)} = new AttachedUIProperty(\"{attachedProperty.Name}\", {DefaultValue(attachedProperty)}{readOnlyParam});");
        }
Пример #5
0
 public AttachedEngineTests()
 {
     sut      = new AttachedPropertyEngine(o => ((BaseObject)o).Parent);
     property = sut.RegisterProperty("Column", typeof(Grid), typeof(int), new AttachedPropertyMetadata {
         DefaultValue = DefaultValue, Inherits = true
     });
 }
Пример #6
0
        public override void Initialize(EditingContext context)
        {
            this.context = context;
            AttachedPropertiesService propertiesService = this.context.Services.GetService <AttachedPropertiesService>();

            helpService = this.context.Services.GetService <IIntegratedHelpService>();

            oldSelection = this.context.Items.GetValue <Selection>();
            isPrimarySelectionProperty = new AttachedProperty <bool>()
            {
                Getter    = (modelItem) => (this.context.Items.GetValue <Selection>().PrimarySelection == modelItem),
                Name      = "IsPrimarySelection",
                OwnerType = typeof(Object)
            };

            isSelectionProperty = new AttachedProperty <bool>()
            {
                Getter    = (modelItem) => (((IList)this.context.Items.GetValue <Selection>().SelectedObjects).Contains(modelItem)),
                Name      = "IsSelection",
                OwnerType = typeof(Object)
            };


            propertiesService.AddProperty(isPrimarySelectionProperty);
            propertiesService.AddProperty(isSelectionProperty);



            if (this.context.Services.GetService <ViewService>() == null)
            {
                view = new System.Activities.Presentation.View.DesignerView(this.context);
                WorkflowViewService      viewService      = new WorkflowViewService(context);
                WorkflowViewStateService viewStateService = new WorkflowViewStateService(context);
                this.context.Services.Publish <ViewService>(viewService);
                this.context.Services.Publish <VirtualizedContainerService>(new VirtualizedContainerService(this.context));
                this.context.Services.Publish <ViewStateService>(viewStateService);
                this.context.Services.Publish <DesignerView>(view);

                WorkflowAnnotationAdornerService annotationService = new WorkflowAnnotationAdornerService();
                annotationService.Initialize(this.context, view.scrollViewer);
                this.context.Services.Publish <AnnotationAdornerService>(annotationService);

                this.context.Services.Subscribe <ModelService>(delegate(ModelService modelService)
                {
                    this.modelService = modelService;
                    if (modelService.Root != null)
                    {
                        view.MakeRootDesigner(modelService.Root);
                    }
                    view.RestoreDesignerStates();
                    this.context.Items.Subscribe <Selection>(new SubscribeContextCallback <Selection>(OnItemSelected));
                });
            }

            if (helpService != null)
            {
                helpService.AddContextAttribute(string.Empty, KeywordForWorkflowDesignerHomePage, HelpKeywordType.F1Keyword);
            }
        }
        JsonObject DumpVisualTree(JsonValue payload)
        {
            var payloadObj      = payload.GetObject();
            var accessibilityId = payloadObj.GetNamedString("accessibilityId");

            var additionalProperties = new List <string>();

            if (payloadObj.ContainsKey("additionalProperties"))
            {
                foreach (JsonValue prop in payloadObj.GetNamedArray("additionalProperties"))
                {
                    additionalProperties.Add(prop.GetString());
                }
            }

            var attachedProperties = new AttachedProperty[] {
                new AttachedProperty()
                {
                    Name = "Top", Property = Microsoft.ReactNative.ViewPanel.TopProperty
                },
                new AttachedProperty()
                {
                    Name = "Left", Property = Microsoft.ReactNative.ViewPanel.LeftProperty
                }
            };
            var rootDump = VisualTreeDumper.DumpTree(this, null, additionalProperties, attachedProperties);
            var element  = VisualTreeDumper.FindElementByAutomationId(JsonObject.Parse(rootDump), accessibilityId);

            if (element != null)
            {
                return(element);
            }

            if (accessibilityId.StartsWith("*"))
            {
                accessibilityId = accessibilityId.Substring(1);

                foreach (var popup in VisualTreeHelper.GetOpenPopups(Window.Current))
                {
                    // XAML's VisualTreeHelper returns 0 for GetChildrenCount of a popup root, so use the popup's child
                    var popupChildDump = VisualTreeDumper.DumpTree(popup.Child, null, additionalProperties, attachedProperties);

                    var json = JsonObject.Parse(popupChildDump);
                    if (accessibilityId == "")
                    {
                        element = json;
                    }
                    else
                    {
                        element = VisualTreeDumper.FindElementByAutomationId(json, accessibilityId);
                    }
                    if (element != null)
                    {
                        break;
                    }
                }
            }
            return(element);
        }
        public void RegisterDouble()
        {
            const string Name = "MyPropertyRegisterDouble";

            _ = AttachedProperty.Register <AttachedPropertyTests, int>(Name);
            new Action(() => _ = AttachedProperty.Register <AttachedPropertyTests, int>(Name)).Should().Throw <ArgumentException>()
            .WithMessage("*already registered*").WithMessage($"*{typeof(AttachedPropertyTests).Name}*").WithMessage($"*{Name}*");
        }
Пример #9
0
        public void ThrowsOnSetNullContext()
        {
            var context          = new AttachedPropertyContext();
            var attachedProperty = new AttachedProperty <object, string>("CanSetAndGet", context);
            var tested           = new object();

            Assert.Throws <ArgumentNullException>(() => tested.SetAttachedValue(attachedProperty, "asdf", null));
        }
Пример #10
0
        public void ThrowsOnGetNullInstance()
        {
            var    context          = new AttachedPropertyContext();
            var    attachedProperty = new AttachedProperty <object, string>("CanSetAndGet", context);
            object tested           = null;

            Assert.Throws <ArgumentNullException>(() => tested.GetAttachedValue(attachedProperty, context));
        }
        public void IsAttached_Returns_True()
        {
            var property = new AttachedProperty <string>(
                "Foo",
                typeof(Class1),
                new StyledPropertyMetadata <string>());

            Assert.True(property.IsAttached);
        }
Пример #12
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="instance"></param>
        /// <param name="attachedProperty"></param>
        /// <param name="value"></param>
        /// <param name="context"></param>
        public static void SetAttachedValue <T, TResult>(this T instance, AttachedProperty <T, TResult> attachedProperty, TResult value, AttachedPropertyContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.SetInstanceValue(instance, attachedProperty, value);
        }
        public void RegisterWithSuffix()
        {
            AttachedProperty <string> property = AttachedProperty.Register <AttachedPropertyTests, string>(() => MyStringProperty, "8");

            property.DefaultValue.Should().Be("8");
            property.DefaultValueUntyped.Should().Be("8");
            property.Name.Should().Be("MyString");
            property.OwnerType.Should().Be <AttachedPropertyTests>();
        }
        public void RegisterAttached()
        {
            AttachedProperty <int> property = AttachedProperty.Register <AttachedPropertyTests, int>("MyPropertyRegisterAttached", 9);

            property.DefaultValue.Should().Be(9);
            property.DefaultValueUntyped.Should().Be(9);
            property.Name.Should().Be("MyPropertyRegisterAttached");
            property.OwnerType.Should().Be <AttachedPropertyTests>();
        }
        public void RegisterWithoutSuffix()
        {
            AttachedProperty <char> property = AttachedProperty.Register <AttachedPropertyTests, char>(() => MyChar, '7');

            property.DefaultValue.Should().Be('7');
            property.DefaultValueUntyped.Should().Be('7');
            property.Name.Should().Be(nameof(MyChar));
            property.OwnerType.Should().Be <AttachedPropertyTests>();
        }
Пример #16
0
        public void IsAttached_Returns_True()
        {
            var property = new AttachedProperty<string>(
                "Foo",
                typeof(Class1),
                new StyledPropertyMetadata<string>());

            Assert.True(property.IsAttached);
        }
Пример #17
0
        public void CanCreate()
        {
            var context = new AttachedPropertyContext();
            var tested  = new AttachedProperty <object, int>("SomeName", context);

            Assert.Equal("System.Object.SomeName", tested.FullName);
            Assert.Equal(typeof(object), tested.OwnerType);
            Assert.Equal(typeof(int), tested.PropertyType);
        }
Пример #18
0
        public void ThrowsOnCreateDuplicate()
        {
            var context = new AttachedPropertyContext();

            var first = new AttachedProperty <object, int>("asdf", context);

            Assert.NotNull(first);
            Assert.Throws <AttachedPropertyException>(() => new AttachedProperty <object, int>("asdf", context));
        }
Пример #19
0
        public void CanGetDefaultWithoutSet()
        {
            var context          = new AttachedPropertyContext();
            var attachedProperty = new AttachedProperty <object, string>("CanGetDefaultWithoutSet", context);
            var tested           = new object();

            var value = tested.GetAttachedValue(attachedProperty, context);

            Assert.Equal(default(string), value);
        }
        public void NullArguments()
        {
            var name           = "MyPropertyCreateNullArguments";
            var nameExpression = (IntPropertyExpression)(() => MyIntProperty);
            var identifier     = new AttachableMemberIdentifier(typeof(AttachedPropertyTests), name);

            new Action(() => _ = AttachedProperty.Register <AttachedPropertyTests, int>((string)null, 1)).Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(name));
            new Action(() => _ = AttachedProperty.Register <AttachedPropertyTests, int>((IntPropertyExpression)null, 1)).Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(nameExpression));
            new Action(() => _ = AttachedProperty.Get(null)).Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(identifier));
        }
        public void Create()
        {
            var identifier = new AttachableMemberIdentifier(typeof(AttachedPropertyTests), "MyPropertyCreate");
            var property   = new AttachedProperty(identifier, "DefaultValue");

            property.DefaultValueUntyped.Should().Be("DefaultValue");
            property.Identifier.Should().Be(identifier);
            property.Name.Should().Be("MyPropertyCreate");
            property.OwnerType.Should().Be <AttachedPropertyTests>();
        }
Пример #22
0
        public void CanSetAndGet()
        {
            var context          = new AttachedPropertyContext();
            var attachedProperty = new AttachedProperty <object, string>("CanSetAndGet", context);
            var tested           = new object();

            tested.SetAttachedValue(attachedProperty, "asdf", context);
            var value = tested.GetAttachedValue(attachedProperty, context);

            Assert.Equal("asdf", value);
        }
Пример #23
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="instance"></param>
        /// <param name="attachedProperty"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static TResult GetAttachedValue <T, TResult>(this T instance, AttachedProperty <T, TResult> attachedProperty, AttachedPropertyContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var value = context.GetInstanceValue(instance, attachedProperty);

            return(value);
        }
Пример #24
0
        public void Registered_Properties_Count_Reflects_Newly_Added_Attached_Property()
        {
            var registry = new AvaloniaPropertyRegistry();
            var metadata = new StyledPropertyMetadata <int>();
            var property = new AttachedProperty <int>("test", typeof(object), metadata, true);

            registry.Register(typeof(object), property);
            registry.RegisterAttached(typeof(AvaloniaPropertyRegistryTests), property);

            Assert.Equal(1, registry.Properties.Count);
        }
Пример #25
0
        public void ThrowsOnGetNotRegistered()
        {
            var context = new AttachedPropertyContext();
            var tested  = new object();

            var attachedProperty = new AttachedProperty <object, int>("asdf", context);

            Assert.Throws <AttachedPropertyException>(() =>
            {
                var _ = tested.GetAttachedValue(attachedProperty);
            });
        }
Пример #26
0
        public void CanGetInstancesDefaultValue()
        {
            var tested = new AttachedPropertyContext();

            var attachedProperty = new AttachedProperty <object, int>("PropertyName", tested);
            var instance         = new object();

            instance.SetAttachedValue(attachedProperty, default(int), tested);
            var instances = tested.GetInstances();

            Assert.Equal(0, instances.Count);
        }
Пример #27
0
        public void CanSetDefaultValueDoesNotStore()
        {
            var tested = new AttachedPropertyContext();

            var attachedProperty = new AttachedProperty <object, string>("CanGetDefaultWithoutSet", tested);
            var instance         = new object();

            instance.SetAttachedValue(attachedProperty, default(string), tested);
            var properties = tested.GetInstanceProperties(instance);

            Assert.Equal(0, properties.Count);
        }
Пример #28
0
        public override void GenerateAttachedPropertyAttachedClassMethods(AttachedProperty attachedProperty, Source methods)
        {
            string targetOutputTypeName   = AttachedTargetOutputTypeName(attachedProperty);
            string propertyOutputTypeName = PropertyOutputTypeName(attachedProperty);
            bool   classPropertyTypeDiffersFromInterface = attachedProperty.Type.ToString() != propertyOutputTypeName;

            methods.AddBlankLineIfNonempty();
            methods.AddLine($"public {propertyOutputTypeName} Get{attachedProperty.Name}({attachedProperty.TargetTypeName} {attachedProperty.TargetParameterName}) => {attachedProperty.Interface.FrameworkClassName}.Get{attachedProperty.Name}(({targetOutputTypeName}) {attachedProperty.TargetParameterName});");
            if (attachedProperty.SetterMethod != null)
            {
                methods.AddLine($"public void Set{attachedProperty.Name}({attachedProperty.TargetTypeName} {attachedProperty.TargetParameterName}, {propertyOutputTypeName} value) => {attachedProperty.Interface.FrameworkClassName}.Set{attachedProperty.Name}(({targetOutputTypeName}) {attachedProperty.TargetParameterName}, value);");
            }
        }
        private void CommentButtonDesigner_OnLoaded(object sender, RoutedEventArgs e)
        {
            AttachedProperty <Type> typeArgumentProperty = new AttachedProperty <Type>
            {
                Name        = TypeArgumentPropertyName,
                OwnerType   = typeof(CommentButton <>),
                Getter      = (modelItem) => modelItem.Parent == null ? null : GetTypeArgument(modelItem),
                Setter      = (modelItem, value) => UpdateTypeArgument(modelItem, value),
                IsBrowsable = true
            };

            Context.Services.GetService <AttachedPropertiesService>().AddProperty(typeArgumentProperty);
        }
Пример #30
0
        public void CanGetNonObjectGetValueNoSet()
        {
            var tested = new AttachedPropertyContext();

            var attachedProperty = new AttachedProperty <object, int>("CanGetNonObjectGetValueNoSet", tested);
            var another          = new AttachedProperty <object, int>("Another", tested);
            var instance         = new object();

            instance.SetAttachedValue(another, 1, tested);
            var value = instance.GetAttachedValue(attachedProperty, tested);

            Assert.Equal(0, value);
        }
            private static AttachedProperty <TTarget, TType> AttachedPropertyFactory(TTarget source, object state)
            {
                var member   = (AttachedBindingMemberInfo <TTarget, TType>)state;
                var property = new AttachedProperty <TTarget, TType> {
                    Value = member.GetDefaultValue(source)
                };

                if (member._memberChangedHandler != null)
                {
                    property.Member = member;
                }
                return(property);
            }