Inheritance: System.Windows.Controls.ListBox
        public SelectColorFromGrid()
        {
            Title = "Select Color from Grid";
            SizeToContent = SizeToContent.WidthAndHeight;

            StackPanel stack = new StackPanel();
            stack.Orientation = Orientation.Horizontal;
            Content = stack;

            Button btn = new Button();
            btn.Content = "Do-nothing button\nto test tabbing";
            btn.Margin = new Thickness(24);
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment = VerticalAlignment.Center;
            stack.Children.Add(btn);

            ColorGridBox clrgrid = new ColorGridBox();
            clrgrid.Margin = new Thickness(24);
            clrgrid.HorizontalAlignment = HorizontalAlignment.Center;
            clrgrid.VerticalAlignment = VerticalAlignment.Center;
            stack.Children.Add(clrgrid);

            clrgrid.SetBinding(ColorGridBox.SelectedValueProperty, "Background");
            clrgrid.DataContext = this;

            btn = new Button();
            btn.Content = "Do-nothing button\nto test tabbing";
            btn.Margin = new Thickness(24);
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment = VerticalAlignment.Center;
            stack.Children.Add(btn);
        }
Example #2
0
        public SelectColorFromGrid()
        {
            Title         = "Select Color from Grid";
            SizeToContent = SizeToContent.WidthAndHeight;

            StackPanel stack = new StackPanel();

            stack.Orientation = Orientation.Horizontal;
            Content           = stack;

            Button btn = new Button();

            btn.Content             = "Do-nothing button\nto test tabbing";
            btn.Margin              = new Thickness(24);
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment   = VerticalAlignment.Center;
            stack.Children.Add(btn);

            ColorGridBox clrgrid = new ColorGridBox();

            clrgrid.Margin = new Thickness(24);
            clrgrid.HorizontalAlignment = HorizontalAlignment.Center;
            clrgrid.VerticalAlignment   = VerticalAlignment.Center;
            stack.Children.Add(clrgrid);

            clrgrid.SetBinding(ColorGridBox.SelectedValueProperty, "Background");
            clrgrid.DataContext = this;

            btn                     = new Button();
            btn.Content             = "Do-nothing button\nto test tabbing";
            btn.Margin              = new Thickness(24);
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment   = VerticalAlignment.Center;
            stack.Children.Add(btn);
        }
        public SelectColorFromMenuGrid()
        {
            Title = "Select Color from Menu Grid";

            //DockPanel   생성
            DockPanel dock = new DockPanel();
            Content = dock;

            //탑 메뉴가 될 Menu 생성
            Menu menu = new Menu();
            dock.Children.Add(menu);
            DockPanel.SetDock(menu, Dock.Top);

            //나머지 영역을 채울 TextBlock을 생성
            TextBlock text = new TextBlock();
            text.Text = Title;
            text.FontSize = 32;
            text.TextAlignment = TextAlignment.Center;
            dock.Children.Add(text);

            //메뉴에 항목을 추가
            MenuItem itemColor = new MenuItem();
            itemColor.Header = "_Color";
            menu.Items.Add(itemColor);

            MenuItem itemForeground = new MenuItem();
            itemForeground.Header = "_Foreground";
            menu.Items.Add(itemForeground);

            //윈도우 전정색과 바인딩되는 ColorGridBox를 생성
            ColorGridBox clrbox = new ColorGridBox();
            clrbox.SetBinding(ColorGridBox.SelectedValueProperty, "Foreground");
            clrbox.DataContext = this;
            itemForeground.Items.Add(clrbox);

            MenuItem itemBackground = new MenuItem();
            itemForeground.Header = "_Background";
            itemColor.Items.Add(itemBackground);

            //윈도우 배경색과 바인딩되는 ColorGridBox를 생성
            clrbox = new ColorGridBox();
            clrbox.SetBinding(ColorGridBox.SelectedValueProperty, "Background");
            clrbox.DataContext = this;
            itemBackground.Items.Add(clrbox);
        }
        public SelectColorFromGrid()
        {
            Title         = "Select Color from Grid";
            SizeToContent = SizeToContent.WidthAndHeight;

            //Создание объекта StackPanel как содержимого окна
            StackPanel stack = new StackPanel();

            stack.Orientation = Orientation.Horizontal;
            Content           = stack;

            //Фиктивная кнопка для проверки передачи фокуса
            Button btn = new Button();

            btn.Content             = "Do-nothing button\nto  test tabbing";
            btn.Margin              = new Thickness(24);
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment   = VerticalAlignment.Center;
            stack.Children.Add(btn);

            //Создание элемента ColorGridBox
            ColorGridBox clrgrid = new ColorGridBox();

            clrgrid.Margin = new Thickness(24);
            clrgrid.HorizontalAlignment = HorizontalAlignment.Center;
            clrgrid.VerticalAlignment   = VerticalAlignment.Center;
            stack.Children.Add(clrgrid);

            // Привязка свойства Background окна к выделенному значению ColorGridBox
            clrgrid.SetBinding(ColorGridBox.SelectedValueProperty, "Background");
            clrgrid.DataContext = this;

            //Создание еще одной фиктивной кнопки
            btn                     = new Button();
            btn.Content             = "Do-nothing button\nto  test tabbing";
            btn.Margin              = new Thickness(24);
            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment   = VerticalAlignment.Center;
            stack.Children.Add(btn);
        }
        void AddCharToolBar(ToolBarTray tray, int band, int index)
        {
            ToolBar toolbar = new ToolBar();
            toolbar.Band = band;
            toolbar.BandIndex = index;
            tray.ToolBars.Add(toolbar);

            comboFamily = new ComboBox();
            comboFamily.Width = 144;
            comboFamily.ItemsSource = Fonts.SystemFontFamilies;
            comboFamily.SelectedItem = txtbox.FontFamily;
            comboFamily.SelectionChanged += FamilyComboOnSelection;
            toolbar.Items.Add(comboFamily);

            ToolTip tip = new ToolTip();
            tip.Content = "Font Family";
            comboFamily.ToolTip = tip;

            comboSize = new ComboBox();
            comboSize.Width = 48;
            comboSize.IsEditable = true;
            comboSize.Text = (0.75 * txtbox.FontSize).ToString();
            comboSize.ItemsSource = new double [] {
                8, 9, 10, 11, 12, 14, 16, 18, 20,
                22, 24, 26, 28, 36, 48, 72
            };
            comboSize.SelectionChanged += SizeComboOnSelection;
            comboSize.GotKeyboardFocus += SizeComboOnGotFocus;
            comboSize.LostKeyboardFocus += SizeComboOnLostFocus;
            comboSize.PreviewKeyDown += SizeComboOnKeyDown;
            toolbar.Items.Add(comboSize);

            tip = new ToolTip();
            tip.Content = "Font Size";
            comboSize.ToolTip = tip;

            btnBold = new ToggleButton();
            btnBold.Checked += BoldButtonOnChecked;
            btnBold.Unchecked += BoldButtonOnChecked;
            toolbar.Items.Add(btnBold);

            string fileName = Path.Combine(Directory.GetCurrentDirectory(), "BoldHS.png");
            Image img = new Image();
            img.Source = new BitmapImage(new Uri(fileName));
            img.Stretch = Stretch.None;
            btnBold.Content = img;

            tip = new ToolTip();
            tip.Content = "Bold";
            btnBold.ToolTip = tip;

            btnItalic = new ToggleButton();
            btnItalic.Checked += ItalicButtonOnChecked;
            btnItalic.Unchecked += ItalicButtonOnChecked;
            toolbar.Items.Add(btnItalic);

            fileName = Path.Combine(Directory.GetCurrentDirectory(), "ItalicHS.png");
            img = new Image();
            img.Stretch = Stretch.None;
            btnItalic.Content = img;

            tip = new ToolTip();
            tip.Content = "Italic";
            btnItalic.ToolTip = tip;

            toolbar.Items.Add(new Separator());

            Menu menu = new Menu();
            toolbar.Items.Add(menu);

            MenuItem item = new MenuItem();
            menu.Items.Add(item);

            fileName = Path.Combine(Directory.GetCurrentDirectory(), "ColorHS.png");
            img = new Image();
            img.Source = new BitmapImage(new Uri(fileName));
            img.Stretch = Stretch.None;
            item.Header = img;

            clrboxBackground = new ColorGridBox();
            clrboxBackground.SelectionChanged += BackgroundOnSelectionChanged;
            item.Items.Add(clrboxBackground);
            tip = new ToolTip();
            tip.Content = "Background Color";
            item.ToolTip = tip;

            item = new MenuItem();
            menu.Items.Add(item);

            fileName = Path.Combine(Directory.GetCurrentDirectory(), "Color_FontHS.png");
            img = new Image();
            img.Source = new BitmapImage(new Uri(fileName));
            img.Stretch = Stretch.None;
            item.Header = img;

            clrboxForeground = new ColorGridBox();
            clrboxForeground.SelectionChanged += ForegroundOnSelectionChanged;
            item.Items.Add(clrboxForeground);

            tip = new ToolTip();
            tip.Content = "Foreground Color";
            item.ToolTip = tip;

            txtbox.SelectionChanged += TextBoxOnSelectionChanged;
        }
        void AddCharToolBar(ToolBarTray tray, int band, int index)
        {
            // Create ToolBar and add to ToolBarTray.
            ToolBar toolbar = new ToolBar();
            toolbar.Band = band;
            toolbar.BandIndex = index;
            tray.ToolBars.Add(toolbar);

            // Create ComboBox for font families.
            comboFamily = new ComboBox();
            comboFamily.Width = 144;
            comboFamily.ItemsSource = Fonts.SystemFontFamilies;
            comboFamily.SelectedItem = txtbox.FontFamily;
            comboFamily.SelectionChanged += FamilyComboOnSelection;
            toolbar.Items.Add(comboFamily);

            ToolTip tip = new ToolTip();
            tip.Content = "Font Family";
            comboFamily.ToolTip = tip;

            // Create ComboBox for font size.
            comboSize = new ComboBox();
            comboSize.Width = 48;
            comboSize.IsEditable = true;
            comboSize.Text = (0.75 * txtbox.FontSize).ToString();
            comboSize.ItemsSource = new double[]
                {
                    8, 9, 10, 11, 12, 14, 16, 18,
                    20, 22, 24, 26, 28, 36, 48, 72
                };
            comboSize.SelectionChanged += SizeComboOnSelection;
            comboSize.GotKeyboardFocus += SizeComboOnGotFocus;
            comboSize.LostKeyboardFocus += SizeComboOnLostFocus;
            comboSize.PreviewKeyDown += SizeComboOnKeyDown;
            toolbar.Items.Add(comboSize);

            tip = new ToolTip();
            tip.Content = "Font Size";
            comboSize.ToolTip = tip;

            // Create Bold button.
            btnBold = new ToggleButton();
            btnBold.Checked += BoldButtonOnChecked;
            btnBold.Unchecked += BoldButtonOnChecked;
            toolbar.Items.Add(btnBold);

            Image img = new Image();
            img.Source = new BitmapImage(
                    new Uri("pack://application:,,/Images/boldhs.png"));
            img.Stretch = Stretch.None;
            btnBold.Content = img;

            tip = new ToolTip();
            tip.Content = "Bold";
            btnBold.ToolTip = tip;

            // Create Italic button.
            btnItalic = new ToggleButton();
            btnItalic.Checked += ItalicButtonOnChecked;
            btnItalic.Unchecked += ItalicButtonOnChecked;
            toolbar.Items.Add(btnItalic);

            img = new Image();
            img.Source = new BitmapImage(
                    new Uri("pack://application:,,/Images/ItalicHS.png"));
            img.Stretch = Stretch.None;
            btnItalic.Content = img;

            tip = new ToolTip();
            tip.Content = "Italic";
            btnItalic.ToolTip = tip;

            toolbar.Items.Add(new Separator());

            // Create Background and Foreground color menu.
            Menu menu = new Menu();
            toolbar.Items.Add(menu);

            // Create Background menu item.
            MenuItem item = new MenuItem();
            menu.Items.Add(item);

            img = new Image();
            img.Source = new BitmapImage(
                    new Uri("pack://application:,,/Images/ColorHS.png"));
            img.Stretch = Stretch.None;
            item.Header = img;

            clrboxBackground = new ColorGridBox();
            clrboxBackground.SelectionChanged += BackgroundOnSelectionChanged;
            item.Items.Add(clrboxBackground);

            tip = new ToolTip();
            tip.Content = "Background Color";
            item.ToolTip = tip;

            // Create Foreground menu item.
            item = new MenuItem();
            menu.Items.Add(item);

            img = new Image();
            img.Source = new BitmapImage(
                    new Uri("pack://application:,,/Images/Color_fontHS.png"));
            img.Stretch = Stretch.None;
            item.Header = img;

            clrboxForeground = new ColorGridBox();
            clrboxForeground.SelectionChanged += ForegroundOnSelectionChanged;
            item.Items.Add(clrboxForeground);

            tip = new ToolTip();
            tip.Content = "Foreground Color";
            item.ToolTip = tip;

            // Install handler for RichTextBox SelectionChanged event.
            txtbox.SelectionChanged += TextBoxOnSelectionChanged;
        }