コード例 #1
0
        void InitializeViews()
        {
            var margin    = new Thickness(0, 0, 0, 0);
            var gridEmpty = new Grid
            {
                Margin            = margin,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //␣
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //\t
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //\n
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    }                                                               //\r
                },
                Children =
                {
                    new CheckBox {
                        Content = "␣", IsChecked = false
                    }.Set(new Action <bool>(v => space.Toggle(v))).Set(0, 0),
                    new CheckBox {
                        Content = "\\t", IsChecked = false
                    }.Set(new Action <bool>(v => t.Toggle(v))).Set(0, 1),
                    new CheckBox {
                        Content = "\\r", IsChecked = false
                    }.Set(new Action <bool>(v => r.Toggle(v))).Set(0, 2),
                    new CheckBox {
                        Content = "\\n", IsChecked = false
                    }.Set(new Action <bool>(v => n.Toggle(v))).Set(0, 3)
                }
            };
            var gridToggle = new Grid
            {
                Margin            = margin,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },                                                               //grieEmpty
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //a~z
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //A~Z
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //0~9
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //Symbols
                },
                Children =
                {
                    gridEmpty.Set(0,    0),
                    new CheckBox {
                        Content = "a",IsChecked = false
                    }.Set(new Action <bool>(v => az.Toggle(v))).Set(0,1),
                    new CheckBox {
                        Content = "A",IsChecked = false
                    }.Set(new Action <bool>(v => AZ.Toggle(v))).Set(0,2),
                    new CheckBox {
                        Content = "0~9",IsChecked = false
                    }.Set(new Action <bool>(v => digit.Toggle(v))).Set(0,3),
                    new CheckBox {
                        Content = "💡",IsChecked = false, ToolTip   = symbols_string
                    }.Set(new Action <bool>(v => symbol.Toggle(v))).Set(0, 4)
                }
            };
            var gridSelect = new Grid
            {
                Margin            = margin,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //Empty
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //中文
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //gridToggle
                },
                Children =
                {
                    new CheckBox {
                        Content = "Empty", IsChecked = Targets.empty, ToolTip = "char.IsWhiteSpace(c)"
                    }.Set(new Action <bool>(v => gridEmpty.IsEnabled = !(Targets.empty = v))).Set(0, 0),
                    new CheckBox {
                        Content = "中", IsChecked = false, ToolTip = "[\\u4e00-\\u9fff]"
                    }.Set(new Action <bool>(v => Targets.chinese = v)).Set(0, 1),
                    gridToggle.Set(0, 2)
                }
            };
            var textBox = new TextBox {
                TextWrapping = TextWrapping.Wrap, ToolTip = "Charactors to be selected.\nDuplicated charactors are acceptable so that you can directly paste an article here."
            };
            var gridPick = new Grid
            {
                Margin            = margin,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Auto)
                    },                                                               //Exclude
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },                                                               //gridPick
                },
                Children =
                {
                    new CheckBox {
                        Content = "Inverse", IsChecked = Targets.exclude, ToolTip = "Selected charactors will be treated as unselected, and vice versa."
                    }.Set(new Action <bool>(
                              v => gridSelect.Background = textBox.Background = new SolidColorBrush((Targets.exclude = v)?Colors.LightGray:Colors.White))).Set(0, 0),
                    gridSelect.Set(0, 1),
                }
            };

            Targets.MatchStringChanged += delegate
            {
                textBox.Text       = Targets.MatchString;
                gridToggle.Opacity = 1;
            };
            this.Content = new Grid
            {
                Margin         = margin,
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    }
                },
                Children =
                {
                    gridPick.Set(0, 0),
                    textBox.Set(new Action <string>(s => { Targets.MatchString = s; gridToggle.Opacity = 0.5; })).Set(1, 0)
                },
            };
        }