/// <summary>
        ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
        /// </summary>
        public EditableContentControl()
        {
            // create the EditModeTemplate definition; there is a limitation
            // that prevents doing this in xaml (child content cannot have the x:Name
            // property set for user controls that are partially defined using xaml)

            //<UserControl.Resources>
            //    <ControlTemplate x:Key="EditModeTemplate"
            //                     TargetType="{x:Type UserControl}">
            //        <TextBox x:Name="textBox"
            //                 Margin="0,0,0,0"
            //                 LostKeyboardFocus="textBox_LostKeyboardFocus"
            //                 PreviewKeyDown="textBox_PreviewKeyDown">
            //        </TextBox>
            //    </ControlTemplate>
            //</UserControl.Resources>

            var factory = new FrameworkElementFactory(typeof(TextBox));

            factory.SetValue(NameProperty, textBoxName);
            factory.AddHandler(LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(textBox_LostKeyboardFocus));
            factory.AddHandler(PreviewKeyDownEvent, new KeyEventHandler(textBox_PreviewKeyDown));
            var editModeTemplate = new ControlTemplate(typeof(EditableContentControl));

            editModeTemplate.VisualTree = factory;
            editModeTemplate.Seal();
            Resources.Add(editModeTemplateKey, editModeTemplate);
        }
Example #2
0
        /// <summary>
        /// Creates a new ControlTemplate
        /// </summary>
        /// <param name="templateType">Type used as template</param>
        /// <param name="targetType">Type used in XAML to insert the template</param>
        /// <returns>A sealed ControlTemplate</returns>
        public static ControlTemplate CreateTemplate(Type templateType, Type targetType)
        {
            ControlTemplate template = new ControlTemplate(targetType)
            {
                VisualTree = new FrameworkElementFactory(templateType)
            };

            template.Seal();
            return(template);
        }
Example #3
0
        internal static FrameworkElement LoadContent(this FrameworkElementFactory visualTree)
        {
            var template = new ControlTemplate()
            {
                VisualTree = visualTree
            };

            template.Seal();
            return(template.LoadContent() as FrameworkElement);
        }
Example #4
0
        static ViewElement()
        {
            var self = typeof(ViewElement);

            var template = new ControlTemplate(self);

            var contentPresenter = new FrameworkElementFactory(typeof(ContentPresenter));

            contentPresenter.SetValue(ContentPresenter.ContentSourceProperty, "View");

            template.VisualTree = contentPresenter;

            template.Seal();

            TemplateProperty.OverrideMetadata(self, new FrameworkPropertyMetadata(template));
        }
Example #5
0
        public LoadingOverlay()
        {
            _adorner = new LoaderAdorner(this);
            var template = new ControlTemplate {
                VisualTree = new FrameworkElementFactory(typeof(LoadingSpinner))
            };

            template.Seal();
            Template = template;
            Loaded  += (s, e) => AdornerLayer.GetAdornerLayer(this).Add(_adorner);
            _adorner.SetBinding(UIElement.VisibilityProperty, new Binding("IsLoading")
            {
                Source    = this,
                Converter = new BooleanToVisibilityConverter(),
                Mode      = BindingMode.OneWay
            });
        }
        static UserControl()
        {
            // UseContentTemplate
            ControlTemplate template = new ControlTemplate();

            template._methodToInstantiateFrameworkTemplate = (owner) =>
            {
                TemplateInstance instance = new TemplateInstance();

                instance.TemplateOwner   = owner;
                instance.TemplateContent = ((UserControl)owner).Content as FrameworkElement;

                return(instance);
            };
            template.Seal();

            UseContentTemplate = template;
        }
        private static ControlTemplate GetIconTemplate()
        {
            var template = new ControlTemplate(typeof(PackIconOcticonsControl));

            var root = new FrameworkElementFactory(typeof(Grid));

            var border = new FrameworkElementFactory(typeof(Border));

            border.SetValue(Control.BackgroundProperty, new TemplateBindingExtension(Control.BackgroundProperty));
            border.SetValue(Control.BorderBrushProperty, new TemplateBindingExtension(Control.BorderBrushProperty));
            border.SetValue(Control.BorderThicknessProperty, new TemplateBindingExtension(Control.BorderThicknessProperty));
            border.SetValue(Control.SnapsToDevicePixelsProperty, new TemplateBindingExtension(Control.SnapsToDevicePixelsProperty));
            root.AppendChild(border);

            var innerGrid = new FrameworkElementFactory(typeof(Grid));

            innerGrid.SetValue(FrameworkElement.MarginProperty, new TemplateBindingExtension(Control.BorderThicknessProperty));

            var path = new FrameworkElementFactory(typeof(Path));

            path.SetValue(Path.FillProperty, new TemplateBindingExtension(Control.ForegroundProperty));
            path.SetValue(Path.StretchProperty, Stretch.Uniform);
            path.SetBinding(Path.DataProperty, new Binding(nameof(PackIconOcticonsControl.Data))
            {
                RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent), Mode = BindingMode.OneWay
            });
            path.SetValue(UIElement.SnapsToDevicePixelsProperty, false);
            path.SetValue(FrameworkElement.UseLayoutRoundingProperty, false);

            var viewBox = new FrameworkElementFactory(typeof(Viewbox));

            viewBox.SetValue(FrameworkElement.MarginProperty, new TemplateBindingExtension(Control.PaddingProperty));

            viewBox.AppendChild(path);
            innerGrid.AppendChild(viewBox);
            root.AppendChild(innerGrid);

            template.VisualTree = root;
            template.Seal();
            return(template);
        }
        private void AddIndicator()
        {
            var separator = new Separator();

            separator.Visibility = Visibility.Hidden;
            separator.Margin     = new Thickness(0.0);
            separator.Width      = 2.0;

            var frameworkElementFactory = new FrameworkElementFactory(typeof(Border));

            frameworkElementFactory.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Black));//Color.FromUInt32(4278190208u)

            var controlTemplate = new ControlTemplate(typeof(Separator));

            controlTemplate.VisualTree = frameworkElementFactory;
            controlTemplate.Seal();

            separator.Template = controlTemplate;

            base.UIChildren.Add(separator);

            this._indicator = separator;
        }
Example #9
0
        public static BaseArcButton CreateBaseArcButton(double size, Position position, string text, double proportion = default(double), double strokeThickness = default(double))
        {
            ArcButton = new BaseArcButton(text, position);
            if (proportion != default(double))
            {
                ArcButton.Proportion = proportion;
            }
            if (strokeThickness != default(double))
            {
                ArcButton.StrokeThickness = strokeThickness;
            }

            var template = new ControlTemplate(typeof(Button));

            #region Triggers

            var mouseOverTrigger = new Trigger
            {
                Property = UIElement.IsMouseOverProperty,
                Value    = true
            };
            mouseOverTrigger.Setters.Add(new Setter
            {
                TargetName = "Path",
                Property   = Shape.StrokeProperty,
                Value      = new Binding
                {
                    Path = new PropertyPath("BorderOver"),
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
                }
            });
            mouseOverTrigger.Setters.Add(new Setter
            {
                TargetName = "Path",
                Property   = Shape.FillProperty,
                Value      = new Binding
                {
                    Path = new PropertyPath("BackgroundOver"),
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
                }
            });

            var pressedTrigger = new Trigger
            {
                Property = Button.IsPressedProperty,
                Value    = true
            };
            pressedTrigger.Setters.Add(new Setter
            {
                TargetName = "Path",
                Property   = Shape.StrokeProperty,
                Value      = new Binding
                {
                    Path = new PropertyPath("BorderBrushPressed"),
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
                }
            });
            pressedTrigger.Setters.Add(new Setter
            {
                TargetName = "Path",
                Property   = Shape.FillProperty,
                Value      = new Binding
                {
                    Path = new PropertyPath("BackgroundPressed"),
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
                }
            });

            template.Triggers.Add(mouseOverTrigger);
            template.Triggers.Add(pressedTrigger);

            #endregion //Triggers

            #region Bindings

            var grid = new FrameworkElementFactory(typeof(Grid), "Grid");
            grid.SetValue(FrameworkElement.HeightProperty, double.NaN);
            grid.SetValue(FrameworkElement.WidthProperty, double.NaN);
            grid.SetValue(UIElement.VisibilityProperty, new Binding
            {
                Path = new PropertyPath("Visibility"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1),
                Converter           = new BoolToVisibilityConverter()
            });

            var path = new FrameworkElementFactory(typeof(Path), "Path");
            path.SetValue(Shape.StrokeThicknessProperty, new Binding
            {
                Path = new PropertyPath("StrokeThickness"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });
            path.SetValue(Shape.FillProperty, new Binding
            {
                Path = new PropertyPath("Background"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });
            path.SetValue(Shape.StrokeProperty, new Binding
            {
                Path = new PropertyPath("BorderBrush"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });

            var textBlock = new FrameworkElementFactory(typeof(TextBlock), "Textblock");
            textBlock.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
            textBlock.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            textBlock.SetValue(UIElement.VisibilityProperty, new Binding
            {
                Path = new PropertyPath("TextVisibility"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1),
                Converter           = new BoolToVisibilityConverter()
            });
            textBlock.SetValue(FrameworkElement.MarginProperty, new Binding
            {
                Path = new PropertyPath("TextMargin"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });
            textBlock.SetValue(TextBlock.FontFamilyProperty, new Binding
            {
                Path = new PropertyPath("FontFamily"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });
            textBlock.SetValue(TextBlock.ForegroundProperty, new Binding
            {
                Path = new PropertyPath("Foreground"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });
            textBlock.SetValue(TextBlock.FontSizeProperty, new Binding
            {
                Path = new PropertyPath("FontSize"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });
            textBlock.SetValue(TextBlock.TextProperty, new Binding
            {
                Path = new PropertyPath("Text"),
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                RelativeSource      = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Button), 1)
            });

            #endregion //Bindings

            #region Position

            Path generatedPath = null;
            switch (position)
            {
            case Position.Left:
                grid.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                grid.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
                textBlock.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                generatedPath = CreateSideButtonPath(size);
                path.SetValue(FrameworkElement.LayoutTransformProperty, new RotateTransform(180));
                path.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                path.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
                ArcButton.Name = "Left";
                break;

            case Position.Top:
                grid.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                grid.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
                generatedPath = CreateSideButtonPath(size);
                path.SetValue(FrameworkElement.LayoutTransformProperty, new RotateTransform(270));
                path.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                path.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
                ArcButton.Name = "Top";
                break;

            case Position.Right:
                grid.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Right);
                grid.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
                textBlock.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                generatedPath = CreateSideButtonPath(size);
                path.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Right);
                path.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
                ArcButton.Name = "Right";
                break;

            case Position.Bottom:
                grid.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                grid.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Bottom);
                generatedPath = CreateSideButtonPath(size);
                path.SetValue(FrameworkElement.LayoutTransformProperty, new RotateTransform(90));
                path.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                path.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Bottom);
                ArcButton.Name = "Bottom";
                break;

            case Position.Center:
                grid.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                grid.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
                generatedPath = CreateCenterButtonPath(size);
                path.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                path.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center);
                ArcButton.Name = "Center";
                break;
            }

            path.SetValue(Path.DataProperty, generatedPath.Data);

            #endregion //Position

            grid.AppendChild(path);
            grid.AppendChild(textBlock);

            template.VisualTree = grid;
            ArcButton.Template  = template;

            template.Seal();

            return(ArcButton);
        }