Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/CS/BarsDemo.Wpf/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/CS/BarsDemo.Wpf/Modules/SimplePad.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Editors.Settings;
using System.Windows.Markup;
using DevExpress.Xpf.Core;
using DevExpress.Xpf;
namespace BarsDemo {
    public partial class SimplePad : BarsDemoModule {
        public SimplePad() {
            InitializeComponent();
        }
        protected override void OnLoaded(object sender, RoutedEventArgs e) {
            base.OnLoaded(sender, e);
            this.richControl.SelectionChanged += OnRichEditControlSelectionChanged;
            ((ComboBoxEditSettings)eFontSize.EditSettings).ItemsSource = (new FontSizes()).Items;
            if(!this.IsInDesignTool())
                this.richControl.Focus();
            OnRichEditControlSelectionChanged(richControl, new EventArgs());
            UpdateUndoRemoBarItems();
        }
        protected override void OnUnloaded(object sender, RoutedEventArgs e) {
            this.richControl.SelectionChanged -= OnRichEditControlSelectionChanged;
            base.OnUnloaded(sender, e);
        }
        protected virtual void OnRichEditControlSelectionChanged(object sender, EventArgs e) {
            this.isUpdatingProccess = true;
            this.eFontFamily.EditValue = this.richControl.TextFontFamily;
            this.eFontSize.EditValue = this.richControl.TextFontSize;

            TextAlignment textAlignment = this.richControl.GetTextAlignment();
            this.bLeft.IsChecked = textAlignment == TextAlignment.Left;
            this.bCenter.IsChecked = textAlignment == TextAlignment.Center;
            this.bRight.IsChecked = textAlignment == TextAlignment.Right;

            this.bBold.IsChecked = this.richControl.TextIsBold;
            this.bItalic.IsChecked = this.richControl.TextIsItalic;
            this.bUnderline.IsChecked = this.richControl.TextIsUnderline;
            this.isUpdatingProccess = false;
            UpdateUndoRemoBarItems();
        }

        protected virtual void bPrint_ItemClick(object sender, ItemClickEventArgs e) {
            this.richControl.Print();
        }
        protected virtual void bUndo_ItemClick(object sender, ItemClickEventArgs e) {

            this.richControl.Undo();
            UpdateUndoRemoBarItems();
        }
        protected virtual void bRedo_ItemClick(object sender, ItemClickEventArgs e) {

            this.richControl.Redo();
            UpdateUndoRemoBarItems();

        }
        protected virtual void UpdateUndoRemoBarItems() {
            this.bUndo.IsEnabled = this.richControl.CanUndo;
            this.bRedo.IsEnabled = this.richControl.CanRedo;
        }
        protected virtual void bCut_ItemClick(object sender, ItemClickEventArgs e) {
            this.richControl.Cut();
        }
        protected virtual void bCopy_ItemClick(object sender, ItemClickEventArgs e) {
            this.richControl.Copy();
        }
        protected virtual void bPaste_ItemClick(object sender, ItemClickEventArgs e) {
            this.richControl.Paste();
        }
        protected virtual void bClear_ItemClick(object sender, ItemClickEventArgs e) {
            this.richControl.Clear();
        }
        protected virtual void bSelectAll_ItemClick(object sender, ItemClickEventArgs e) {
            this.richControl.SelectAll();
        }
        protected virtual void bHome_ItemClick(object sender, ItemClickEventArgs e) {

            System.Diagnostics.Process.Start("http://www.devexpress.com");
        }
        protected virtual void bNew_ItemClick(object sender, EventArgs e) {
            this.richControl.Clear();
        }
        protected virtual void bClose_ItemClick(object sender, EventArgs e) {
            this.richControl.Clear();
        }

        protected virtual void eFontFamily_EditValueChanged(object sender, EventArgs e) {
            if(this.isUpdatingProccess)
                return;
            this.richControl.TextFontFamily = this.eFontFamily.EditValue;
            this.richControl.Focus();
        }
        protected virtual void eFontSize_EditValueChanged(object sender, EventArgs e) {
            if(this.isUpdatingProccess)
                return;
            this.richControl.TextFontSize = this.eFontSize.EditValue;
            this.richControl.Focus();
        }
        protected virtual void bFontColor_ItemClick(object sender, EventArgs e) {
            this.richControl.TextColor = SelectedColor;
        }
        protected virtual void fontColorChooser_ColorChanged(object sender, EventArgs e) {
            SelectedColor = ((ColorChooser)sender).Color;
            this.richControl.Focus();
        }
        protected virtual void bLeft_CheckedChanged(object sender, EventArgs e) {
            if(this.isUpdatingProccess || this.richControl == null)
                return;
            if((bool)this.bLeft.IsChecked) this.richControl.ToggleTextAlignmentLeft();
        }
        protected virtual void bCenter_CheckedChanged(object sender, EventArgs e) {
            if(this.isUpdatingProccess || this.richControl == null)
                return;
            if((bool)this.bCenter.IsChecked) this.richControl.ToggleTextAlignmentCenter();
        }
        protected virtual void bRight_CheckedChanged(object sender, EventArgs e) {
            if(this.isUpdatingProccess || this.richControl == null)
                return;
            if((bool)this.bRight.IsChecked) this.richControl.ToggleTextAlignmentRight();
        }
        protected virtual void bBold_ItemClick(object sender, EventArgs e) {
            if(this.isUpdatingProccess)
                return;
            this.richControl.TextIsBold = (bool)this.bBold.IsChecked;
        }
        protected virtual void bItalic_ItemClick(object sender, EventArgs e) {
            if(this.isUpdatingProccess)
                return;
            this.richControl.TextIsItalic = (bool)this.bItalic.IsChecked;
        }
        protected virtual void bUnderline_ItemClick(object sender, EventArgs e) {
            if(this.isUpdatingProccess)
                return;
            this.richControl.TextIsUnderline = (bool)this.bUnderline.IsChecked;
        }

        Color selectedColor = Colors.Black;
        Color SelectedColor {
            get { return this.selectedColor; }
            set {
                this.selectedColor = value;
                if(this.richControl != null)
                    this.richControl.TextColor = value;
            }
        }
        bool isUpdatingProccess = false;

        private void bAbout_ItemClick(object sender, ItemClickEventArgs e) {
            string platformName = "WPF";
            AboutToolInfo ati = new AboutToolInfo();
            ati.LicenseState = LicenseState.Licensed;
            ati.ProductDescriptionLine1 = "A demo application that demonstrates the Toolbar and Menu system providing commands for a simple text editor.";
            ati.ProductDescriptionLine2 = "In this demo, the DevExpress Toolbar and Menu library is used to implement text editing commands in a simple text editor.";
            ati.ProductDescriptionLine3 = "Practice using bar commands to control the appearance of the editor's text. To learn more about DevExpress visit:";
            ati.ProductEULA = "DevExpress";
            ati.ProductEULAUri = "http://www.devexpress.com/";
            ati.ProductName = "DXBars for " + platformName;
            ati.Version = AssemblyInfo.MarketingVersion;

            DevExpress.Xpf.ToolAbout tAbout = new ToolAbout(ati);
            AboutWindow aWindow = new AboutWindow();
            aWindow.Content = tAbout;
            aWindow.ShowDialog();
        }
    }
    public class FontSizes {
        public int?[] Items {
            get {
                return new int?[] {
                    null, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30,
                    32, 34, 36, 38, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 88, 96, 104, 112, 120, 128, 136, 144
                };
            }
        }
    }
    public class TextExtension : MarkupExtension {
        public string Text { get; set; }
        public TextExtension() {
        }
        public TextExtension(string value) {
            Text = value;
        }
        public override object ProvideValue(IServiceProvider serviceProvider) {
            return Text;
        }
    }
}