Ejemplo n.º 1
0
            private void SetOutputProperty(AnnotationCollection inputAnnotation)
            {
                var avail   = inputAnnotation.Get <IAvailableValuesAnnotation>();
                var setVal  = avail as IAvailableValuesSelectedAnnotation;
                var options = avail.AvailableValues.Cast <object>().ToArray();

                setVal.SelectedValue = options[1];
            }
Ejemplo n.º 2
0
        /// <summary>
        /// If the member has a PictureAttribute and it support being a string value, then it can probably be loaded as an image.
        /// </summary>
        /// <param name="annotation"></param>
        /// <returns></returns>
        public FrameworkElement CreateControl(AnnotationCollection annotation)
        {
            // [Picture] is used.
            bool ispic = annotation.Get <IMemberAnnotation>()?.Member.HasAttribute <PictureAttribute>() ?? false;

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

            // It is something that acts like a string.
            var stringValueProvider = annotation.Get <IStringValueAnnotation>();

            if (stringValueProvider == null)
            {
                return(null);
            }

            // create a WPF image control.
            var img = new Image();

            BindingOperations.SetBinding(img, Image.SourceProperty,
                                         new Binding(nameof(IStringValueAnnotation.Value))
            {
                Source    = stringValueProvider,
                Converter = new FileToImageConverter()     // this converter converts a file path (local or web) to an image source.
            });

            // ** Performance Notice **
            // This way of showing an image is quite slow. If it is a large image from a slow network drive it could cause the GUI to lag whenever the step is selected.
            // consider adding in memory caching of that is the case. For brevity this is not shown here.
            //

            // Get updates when changes happen to the annotation. For example when the value has changed.
            var update = annotation.Get <UpdateMonitor>(true);

            if (update != null)
            {
                // When the value changes explicitly reload the SourceProperty of the image.
                update.RegisterSourceUpdated(img, () => img.GetBindingExpression(Image.SourceProperty).UpdateTarget());
            }

            return(img);
        }
Ejemplo n.º 3
0
        public void Annotate(AnnotationCollection annotations)
        {
            var member = annotations.Get <IMemberAnnotation>()?.Member;

            if (member == null)
            {
                return;
            }
            if (member.TypeDescriptor == TypeData.FromType(typeof(IPAddress)) == false)
            {
                return;
            }

            // now its known that it is an IPAddress
            annotations.Add(new IPAnnotation(annotations));
        }