protected void FontSize(object sender, WriterCommandEventArgs args)
 {
     if (args.Mode == WriterCommandEventMode.InitalizeUIElement)
     {
         if (args.UIElement is ToolStripComboBox)
         {
             ToolStripComboBox cbo = (ToolStripComboBox)args.UIElement;
             if (cbo.Items.Count == 0)
             {
                 foreach (FontSizeInfo info in FontSizeInfo.StandSizes)
                 {
                     cbo.Items.Add(info.Name);
                 }
             }
         }
         if (args.UIElement is ComboBox)
         {
             ComboBox cbo = (ComboBox)args.UIElement;
             if (cbo.Items.Count == 0)
             {
                 foreach (FontSizeInfo info in FontSizeInfo.StandSizes)
                 {
                     cbo.Items.Add(info.Name);
                 }
             }
         }
     }
     else if (args.Mode == WriterCommandEventMode.QueryState)
     {
         args.Enabled = args.DocumentControler != null &&
                        args.DocumentControler.Snapshot.CanModifySelection;
         args.Parameter = FontSizeInfo.GetStandSizeName(GetCurrentStyle(args.Document).FontSize);
     }
     else if (args.Mode == WriterCommandEventMode.Invoke)
     {
         SetStyleProperty(sender, args, StandardCommandNames.FontSize);
         if (args.EditorControl != null)
         {
             args.EditorControl.Focus();
         }
     }
 }
        private void SetStyleProperty(
            object sender,
            WriterCommandEventArgs args,
            string commandName)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                DocumentContentStyle style = GetCurrentStyle(args.Document);
                args.Enabled = args.DocumentControler != null &&
                               args.DocumentControler.Snapshot.CanModifySelection;
                switch (commandName)
                {
                case StandardCommandNames.Bold:
                    args.Checked = style.Bold;
                    break;

                case StandardCommandNames.BorderBottom:
                    args.Checked = style.BorderBottom;
                    break;

                case StandardCommandNames.BorderLeft:
                    args.Checked = style.BorderLeft;
                    break;

                case StandardCommandNames.BorderRight:
                    args.Checked = style.BorderRight;
                    break;

                case StandardCommandNames.BorderTop:
                    args.Checked = style.BorderTop;
                    break;

                case StandardCommandNames.Italic:
                    args.Checked = style.Italic;
                    break;

                case StandardCommandNames.Strikeout:
                    args.Checked = style.Strikeout;
                    break;

                case StandardCommandNames.Subscript:
                    args.Checked = style.Subscript;
                    break;

                case StandardCommandNames.Superscript:
                    args.Checked = style.Superscript;
                    break;

                case StandardCommandNames.Underline:
                    args.Checked = style.Underline;
                    break;

                default:
                    args.Enabled = false;
                    return;
                }
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                DocumentContentStyle cs = GetCurrentStyle(args.Document);
                DocumentContentStyle ns = args.Document.CreateDocumentContentStyle();
                ns.DisableDefaultValue = true;
                switch (commandName)
                {
                case StandardCommandNames.Bold:
                    if (args.Parameter is bool)
                    {
                        ns.Bold = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.Bold = !cs.Bold;
                    }
                    break;

                case StandardCommandNames.BorderBottom:
                    if (args.Parameter is bool)
                    {
                        ns.BorderBottom = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.BorderBottom = !cs.BorderBottom;
                    }
                    break;

                case StandardCommandNames.BorderLeft:
                    if (args.Parameter is bool)
                    {
                        ns.BorderLeft = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.BorderLeft = !cs.BorderLeft;
                    }
                    break;

                case StandardCommandNames.BorderRight:
                    if (args.Parameter is bool)
                    {
                        ns.BorderRight = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.BorderRight = !cs.BorderRight;
                    }
                    break;

                case StandardCommandNames.BorderTop:
                    if (args.Parameter is bool)
                    {
                        ns.BorderTop = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.BorderTop = !cs.BorderTop;
                    }
                    break;

                case StandardCommandNames.Italic:
                    if (args.Parameter is bool)
                    {
                        ns.Italic = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.Italic = !cs.Italic;
                    }
                    break;

                case StandardCommandNames.Strikeout:
                    if (args.Parameter is bool)
                    {
                        ns.Strikeout = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.Strikeout = !cs.Strikeout;
                    }
                    break;

                case StandardCommandNames.Subscript:
                    if (args.Parameter is bool)
                    {
                        ns.Subscript = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.Subscript = !cs.Subscript;
                    }
                    ns.Superscript = false;
                    break;

                case StandardCommandNames.Superscript:
                    ns.Subscript = false;
                    if (args.Parameter is bool)
                    {
                        ns.Superscript = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.Superscript = !cs.Superscript;
                    }
                    break;

                case StandardCommandNames.Underline:
                    if (args.Parameter is bool)
                    {
                        ns.Underline = (bool)args.Parameter;
                    }
                    else
                    {
                        ns.Underline = !cs.Underline;
                    }
                    break;

                case StandardCommandNames.Color:
                    if (args.Parameter is Color)
                    {
                        ns.Color = (Color)args.Parameter;
                    }
                    break;

                case StandardCommandNames.BackColor:
                    if (args.Parameter is Color)
                    {
                        ns.BackgroundColor = (Color)args.Parameter;
                    }
                    break;

                case StandardCommandNames.Font:
                    if (args.Parameter is Font)
                    {
                        ns.Font = new XFontValue((Font)args.Parameter);
                    }
                    else if (args.Parameter is XFontValue)
                    {
                        ns.Font = ((XFontValue)args.Parameter).Clone();
                    }
                    break;

                case StandardCommandNames.FontName:
                    if (args.Parameter is string)
                    {
                        ns.FontName = (string)args.Parameter;
                        args.Document.EditorCurrentStyle.FontName = ns.FontName;
                        //if (args.EditorControl != null)
                        //{
                        //    args.EditorControl.Focus();
                        //}
                    }
                    break;

                case StandardCommandNames.FontSize:
                    if (args.Parameter is string)
                    {
                        ns.FontSize = FontSizeInfo.GetFontSize((string)args.Parameter, args.Document.DefaultStyle.FontSize);
                    }
                    else if (args.Parameter is float ||
                             args.Parameter is double ||
                             args.Parameter is int)
                    {
                        ns.FontSize = Convert.ToSingle(args.Parameter);
                    }
                    args.Document.EditorCurrentStyle.FontSize = ns.FontSize;
                    //if (args.EditorControl != null)
                    //{
                    //    args.EditorControl.Focus();
                    //}
                    break;

                default:
                    throw new NotSupportedException(commandName);
                }//switch
                XDependencyObject.MergeValues(ns, args.Document.EditorCurrentStyle, true);
                if (args.Document.Selection.Length != 0)
                {
                    args.Document.BeginLogUndo();
                    args.Document.Selection.SetElementStyle(ns);
                    args.Document.EndLogUndo();
                    args.Document.OnSelectionChanged();
                    args.Document.OnDocumentContentChanged();
                }
                //args.Document.CurrentStyle.Underline = v;
            }
        }