コード例 #1
0
        /// <summary>
        /// Creates the default input mode for the GraphControl,
        /// a <see cref="GraphEditorInputMode"/>.
        /// </summary>
        /// <remarks>
        /// This implementation configures label text validation
        /// </remarks>
        /// <returns>A new GraphEditorInputMode instance</returns>
        protected virtual IInputMode CreateEditorMode()
        {
            var graphEditorInputMode = new GraphEditorInputMode();

            //Configure label text validation
            // Note that by default, no visual feedback is provided, the text is just not changed
            graphEditorInputMode.ValidateLabelText += delegate(object o, LabelTextValidatingEventArgs args) {
                if (args.Label == pageHeader)
                {
                    // Page header may not be empty, regardless of whether validation is enabled or not
                    args.Cancel = args.NewText == String.Empty;
                }
                else
                {
                    // label must match the pattern
                    args.Cancel = validationEnabled && !validationPattern.IsMatch(args.NewText);
                }
            };

            // The label size for the dummy label must be updated externally
            graphEditorInputMode.LabelTextChanged += delegate(object o, LabelEventArgs args) {
                if (args.Item == pageHeader)
                {
                    pageHeader.AdoptPreferredSizeFromStyle();
                }
            };

            // Instant typing requires a custom TextEditorInputMode - it's safe to use it globally, though
            graphEditorInputMode.TextEditorInputMode = textEditorInputMode = new DemoTextEditorInputMode();

            return(graphEditorInputMode);
        }
コード例 #2
0
        /// <summary>Creates the label for the page header.</summary>
        /// <remarks>
        /// The page header is a dummy labeled that is anchored at a fixed location. FreeLabelModel allows arbitrary positioning.
        /// In this case, we anchor the label to a dynamic point that always corresponds to the upper left corner of the viewport.
        /// We use the ZoomInvariantLabelStyle from the tutorial to ensure we always look the same
        /// </remarks>
        public static SimpleLabel CreatePageHeader(GraphControl graphControl)
        {
            var innerLabelStyle = new DefaultLabelStyle
            {
                Typeface        = new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal),
                TextSize        = 20,
                BackgroundPen   = Pens.Green,
                TextBrush       = Brushes.White,
                BackgroundBrush = Brushes.Green
            };
            var headerLabel = new SimpleLabel(null, "Page Header", FreeLabelModel.Instance.CreateAnchored(
                                                  new DynamicViewPoint(graphControl, 5, 30)))
            {
                Style = new ZoomInvariantLabelStyle(innerLabelStyle)
            };

            // Adjust the size so that the text fits
            headerLabel.AdoptPreferredSizeFromStyle();

            // Since we don't have a model item for the label, we add the label's visual creator directly
            // to the scene graph
            var headerCanvasObject = graphControl.RootGroup.AddChild(new PageHeaderVisualCreator(headerLabel));

            var pageHeaderLabelEditHelper = new PageHeaderEditLabelHelper(headerLabel, headerCanvasObject);

            headerLabel.LookupImplementation = Lookups.Single <IEditLabelHelper>(pageHeaderLabelEditHelper);

            return(headerLabel);
        }