public static void SetFontSize(RichTextBox target, double value)
        {
            // Make sure we have a richtextbox.
            if (target == null)
                return;

            // Make sure we have a selection. Should have one even if there is no text selected.
            if (target.Selection != null)
            {
                // Check whether there is text selected or just sitting at cursor
                if (target.Selection.IsEmpty)
                {
                    // Check to see if we are at the start of the textbox and nothing has been added yet
                    if (target.Selection.Start.Paragraph == null)
                    {
                        // Add a new paragraph object to the richtextbox with the fontsize
                        Paragraph p = new Paragraph();
                        p.FontSize = value;
                        target.Document.Blocks.Add(p);
                    }
                    else
                    {
                        // Get current position of cursor
                        TextPointer curCaret = target.CaretPosition;
                        // Get the current block object that the cursor is in
                        Block curBlock = target.Document.Blocks.Where
                            (x => x.ContentStart.CompareTo(curCaret) == -1 && x.ContentEnd.CompareTo(curCaret) == 1).FirstOrDefault();
                        if (curBlock != null)
                        {
                            Paragraph curParagraph = curBlock as Paragraph;
                            // Create a new run object with the fontsize, and add it to the current block
                            Run newRun = new Run();
                            newRun.FontSize = value;
                            curParagraph.Inlines.Add(newRun);
                            // Reset the cursor into the new block. 
                            // If we don't do this, the font size will default again when you start typing.
                            target.CaretPosition = newRun.ElementStart;
                        }
                    }
                }
                else // There is selected text, so change the fontsize of the selection
                {
                    TextRange selectionTextRange = new TextRange(target.Selection.Start, target.Selection.End);
                    selectionTextRange.ApplyPropertyValue(TextElement.FontSizeProperty, value);
                }
            }
            // Reset the focus onto the richtextbox after selecting the font in a toolbar etc
            target.Focus();
        }
Ejemplo n.º 2
0
        private static RichTextBox ProvideRichTextBoxControl(Binding binding, PropertyInfo propertyInfo)
        {
            var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>();


            var control = new RichTextBox();

            control.SetBinding(RichTextBox.TextProperty, binding);
            control.TextFormatter = new PlainTextFormatter();

            //add formatBar
            var formatBar = new RichTextBoxFormatBar();

            RichTextBoxFormatBarManager.SetFormatBar(control, formatBar);


            control.IsReadOnly = propertyInfo.IsControlReadonly();

            return(control);
        }
Ejemplo n.º 3
0
        private static RichTextBox ProvideRichTextBoxControl(Binding binding, PropertyInfo propertyInfo)
        {
            var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>();


            var control = new RichTextBox();

            control.SetBinding(RichTextBox.TextProperty, binding);
            control.TextFormatter = new PlainTextFormatter();

            //add formatBar
            var formatBar = new RichTextBoxFormatBar();

            RichTextBoxFormatBarManager.SetFormatBar(control, formatBar);


            control.IsReadOnly = (editableAttribute != null && !editableAttribute.AllowEdit) ||
                                 binding.Mode == BindingMode.OneWay;

            return(control);
        }
Ejemplo n.º 4
0
        private LogViewModelEntry ParseAndAddLogEntry(BsonDocument entry, int entryNumber)
        {
            DateTime time = entry.GetValue("time").AsDateTime;
            string category = entry.GetValue("category").AsString;
            string format = entry.GetValue("message").AsString;
            BsonArray args = entry.GetValue("args").AsBsonArray;

            Paragraph paragraph = new Paragraph();
            string current = "";
            int i = 0;
            int n = 0;

            bool arrayHack = (format.Count(x => x == '{') == 1 && args.Count > 1);

            while (i < format.Length)
            {
                if (format[i] != '{')
                    current += format[i];
                else
                {
                    paragraph.Inlines.Add(new Run(current));
                    string token = "";
                    i++;
                    while (i < format.Length && format[i] != '}')
                        token += format[i++];

                    if (i < format.Length && format[i] == '}')
                    {
                        var run = new Run(token);
                        run.Foreground = Brushes.MediumBlue;
                        run.Cursor = Cursors.Hand;
                        int localN = n;
                        if (arrayHack)
                            run.MouseDown += delegate { ShowObject(args); };
                        else
                            run.MouseDown += delegate { ShowObject(args[localN]); };
                        paragraph.Inlines.Add(run);
                    }

                    n++;
                    current = "";
                }
                i++;
            }
            if (current != "")
                paragraph.Inlines.Add(new Run(current));

            var flowDoc = new FlowDocument(paragraph);
            flowDoc.FontFamily = new FontFamily("lucida");
            var msgRtb = new RichTextBox(flowDoc);
            msgRtb.IsReadOnly = true;
            var result = new LogViewModelEntry()
            {
                N = entryNumber,
                Time = time,
                Category = category,
                Message = msgRtb,
            };

            return result;
        }
Ejemplo n.º 5
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.UserControl = ((Dota2ls.UserControl1)(target));
                return;

            case 2:
                this.LayoutRoot = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.Tooltip_item_1 = ((System.Windows.Controls.Primitives.Popup)(target));
                return;

            case 4:
                this.Border_tip = ((System.Windows.Controls.Border)(target));
                return;

            case 5:
                this.Tip_grid = ((System.Windows.Controls.Grid)(target));
                return;

            case 6:
                this.Tip_1_Pic = ((System.Windows.Controls.Image)(target));
                return;

            case 7:
                this.Tip_1_Name = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.Tip_1_Id = ((System.Windows.Controls.Label)(target));
                return;

            case 9:
                this.gold_ico = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 10:
                this.Tip_1_Gold = ((System.Windows.Controls.Label)(target));
                return;

            case 11:
                this.Tip_1_Description = ((Microsoft.Windows.Controls.RichTextBox)(target));
                return;

            case 12:
                this.cd_ico = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 13:
                this.Tip_1_Cooldown = ((System.Windows.Controls.Label)(target));
                return;

            case 14:
                this.Tip_1_Lore = ((Microsoft.Windows.Controls.RichTextBox)(target));
                return;

            case 15:
                this.Tip_1_Attrib = ((Microsoft.Windows.Controls.RichTextBox)(target));
                return;

            case 16:
                this.Tip_1_Notes = ((Microsoft.Windows.Controls.RichTextBox)(target));
                return;

            case 17:
                this.Tooltip_hero = ((System.Windows.Controls.Primitives.Popup)(target));
                return;

            case 18:
                this.Hero_Border_tip = ((System.Windows.Controls.Border)(target));
                return;

            case 19:
                this.Hero_grid = ((System.Windows.Controls.Grid)(target));
                return;

            case 20:
                this.Hero_Pic = ((System.Windows.Controls.MediaElement)(target));
                return;

            case 21:
                this.Hero_features = ((System.Windows.Controls.MediaElement)(target));
                return;

            case 22:
                this.Hero_Id = ((System.Windows.Controls.Label)(target));
                return;

            case 23:
                this.NameHeroLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 24:
                this.IDLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 25:
                this.DLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 26:
                this.ALebel = ((System.Windows.Controls.Label)(target));
                return;

            case 27:
                this.KLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 28:
                this.GoldLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 29:
                this.LHLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 30:
                this.DNLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 31:
                this.XPMLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 32:
                this.GPMLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 33:
                this.TGLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 34:
                this.DMGLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 35:
                this.TDLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 36:
                this.PicHero = ((System.Windows.Controls.Image)(target));

            #line 124 "..\..\UserControl1.xaml"
                this.PicHero.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicHero_MouseEnter);

            #line default
            #line hidden

            #line 124 "..\..\UserControl1.xaml"
                this.PicHero.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicHero_MouseLeave);

            #line default
            #line hidden
                return;

            case 37:
                this.PicItem1 = ((System.Windows.Controls.Image)(target));

            #line 126 "..\..\UserControl1.xaml"
                this.PicItem1.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicItem1_MouseEnter);

            #line default
            #line hidden

            #line 126 "..\..\UserControl1.xaml"
                this.PicItem1.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicItem1_MouseLeave);

            #line default
            #line hidden
                return;

            case 38:
                this.PicItem2 = ((System.Windows.Controls.Image)(target));

            #line 131 "..\..\UserControl1.xaml"
                this.PicItem2.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicItem2_MouseEnter);

            #line default
            #line hidden

            #line 131 "..\..\UserControl1.xaml"
                this.PicItem2.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicItem2_MouseLeave);

            #line default
            #line hidden
                return;

            case 39:
                this.PicItem3 = ((System.Windows.Controls.Image)(target));

            #line 136 "..\..\UserControl1.xaml"
                this.PicItem3.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicItem3_MouseEnter);

            #line default
            #line hidden

            #line 136 "..\..\UserControl1.xaml"
                this.PicItem3.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicItem3_MouseLeave);

            #line default
            #line hidden
                return;

            case 40:
                this.PicItem4 = ((System.Windows.Controls.Image)(target));

            #line 141 "..\..\UserControl1.xaml"
                this.PicItem4.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicItem4_MouseEnter);

            #line default
            #line hidden

            #line 141 "..\..\UserControl1.xaml"
                this.PicItem4.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicItem4_MouseLeave);

            #line default
            #line hidden
                return;

            case 41:
                this.PicItem5 = ((System.Windows.Controls.Image)(target));

            #line 146 "..\..\UserControl1.xaml"
                this.PicItem5.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicItem5_MouseEnter);

            #line default
            #line hidden

            #line 146 "..\..\UserControl1.xaml"
                this.PicItem5.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicItem5_MouseLeave);

            #line default
            #line hidden
                return;

            case 42:
                this.PicItem6 = ((System.Windows.Controls.Image)(target));

            #line 151 "..\..\UserControl1.xaml"
                this.PicItem6.MouseEnter += new System.Windows.Input.MouseEventHandler(this.PicItem6_MouseEnter);

            #line default
            #line hidden

            #line 151 "..\..\UserControl1.xaml"
                this.PicItem6.MouseLeave += new System.Windows.Input.MouseEventHandler(this.PicItem6_MouseLeave);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }