コード例 #1
0
        void InitializeOperandType(InstructionOperandVM instructionOperandVM)
        {
            switch (instructionOperandVM.InstructionOperandType)
            {
            case InstructionOperandType.None:
                Content = null;
                break;

            case InstructionOperandType.SByte:
            case InstructionOperandType.Byte:
            case InstructionOperandType.Int32:
            case InstructionOperandType.Int64:
            case InstructionOperandType.Single:
            case InstructionOperandType.Double:
            case InstructionOperandType.String:
                // Don't cache the TextBox as a field in this class. The error border disappears when
                // switching from a textbox opcode to a non-textbox opcode and back to the textbox
                // again. Only solution seems to be to create a new textbox.
                var textBox = Content as TextBox;
                if (textBox == null)
                {
                    textBox = new TextBox();
                    var binding = new Binding("InstructionOperandVM.Text.StringValue")
                    {
                        Source = this,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                    };
                    textBox.SetBinding(TextBox.TextProperty, binding);
                    binding = new Binding("TextBoxStyle")
                    {
                        Source = this,
                    };
                    textBox.SetBinding(TextBox.StyleProperty, binding);
                    Content = textBox;
                }
                break;

            case InstructionOperandType.Field:
            case InstructionOperandType.Method:
            case InstructionOperandType.Token:
            case InstructionOperandType.Type:
            case InstructionOperandType.MethodSig:
            case InstructionOperandType.SwitchTargets:
                var button = Content as FastClickButton;
                if (button == null)
                {
                    button = new FastClickButton();
                    var binding = new Binding("InstructionOperandVM.Other")
                    {
                        Source                = this,
                        Mode                  = BindingMode.OneWay,
                        Converter             = CilObjectConverter.Instance,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                    };
                    button.SetBinding(Button.ContentProperty, binding);
                    binding = new Binding("ButtonStyle")
                    {
                        Source = this,
                    };
                    button.SetBinding(Button.StyleProperty, binding);
                    binding = new Binding("ButtonCommand")
                    {
                        Source = this,
                    };
                    button.SetBinding(Button.CommandProperty, binding);
                    button.CommandParameter = button;
                    Content = button;
                }
                break;

            case InstructionOperandType.BranchTarget:
            case InstructionOperandType.Local:
            case InstructionOperandType.Parameter:
                var comboBox = Content as ComboBox;
                if (comboBox == null)
                {
                    comboBox = new ComboBox();
                    comboBox.ItemTemplate = (DataTemplate)GetValue(ComboBoxItemTemplateProperty);
                    ComboBoxAttachedProps.SetSelectionBoxItemTemplate(comboBox, (DataTemplate)GetValue(ComboBoxSelectionBoxItemTemplateProperty));
                    var binding = new Binding("InstructionOperandVM.OperandListVM.Items")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, binding);
                    binding = new Binding("InstructionOperandVM.OperandListVM.SelectedIndex")
                    {
                        Source = this,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                    };
                    comboBox.SetBinding(ComboBox.SelectedIndexProperty, binding);
                    binding = new Binding("ComboBoxStyle")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.StyleProperty, binding);
                    binding = new Binding("ComboBoxItemTemplate")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.ItemTemplateProperty, binding);
                    binding = new Binding("ComboBoxSelectionBoxItemTemplate")
                    {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBoxAttachedProps.SelectionBoxItemTemplateProperty, binding);
                    Content = comboBox;
                }
                break;

            default: throw new InvalidOperationException();
            }
        }
コード例 #2
0
        void InitializeOperandType(InstructionOperandVM instructionOperandVM)
        {
            switch (instructionOperandVM.InstructionOperandType) {
            case InstructionOperandType.None:
                Content = null;
                break;

            case InstructionOperandType.SByte:
            case InstructionOperandType.Byte:
            case InstructionOperandType.Int32:
            case InstructionOperandType.Int64:
            case InstructionOperandType.Single:
            case InstructionOperandType.Double:
            case InstructionOperandType.String:
                // Don't cache the TextBox as a field in this class. The error border disappears when
                // switching from a textbox opcode to a non-textbox opcode and back to the textbox
                // again. Only solution seems to be to create a new textbox.
                var textBox = Content as TextBox;
                if (textBox == null) {
                    textBox = new TextBox();
                    var binding = new Binding("InstructionOperandVM.Text.StringValue") {
                        Source = this,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    };
                    textBox.SetBinding(TextBox.TextProperty, binding);
                    binding = new Binding("TextBoxStyle") {
                        Source = this,
                    };
                    textBox.SetBinding(TextBox.StyleProperty, binding);
                    Content = textBox;
                }
                break;

            case InstructionOperandType.Field:
            case InstructionOperandType.Method:
            case InstructionOperandType.Token:
            case InstructionOperandType.Type:
            case InstructionOperandType.MethodSig:
            case InstructionOperandType.SwitchTargets:
                var button = Content as FastClickButton;
                if (button == null) {
                    button = new FastClickButton();
                    var binding = new Binding("InstructionOperandVM.Other") {
                        Source = this,
                        Mode = BindingMode.OneWay,
                        Converter = CilObjectConverter.Instance,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    };
                    button.SetBinding(Button.ContentProperty, binding);
                    binding = new Binding("ButtonStyle") {
                        Source = this,
                    };
                    button.SetBinding(Button.StyleProperty, binding);
                    binding = new Binding("ButtonCommand") {
                        Source = this,
                    };
                    button.SetBinding(Button.CommandProperty, binding);
                    button.CommandParameter = button;
                    Content = button;
                }
                break;

            case InstructionOperandType.BranchTarget:
            case InstructionOperandType.Local:
            case InstructionOperandType.Parameter:
                var comboBox = Content as ComboBox;
                if (comboBox == null) {
                    comboBox = new ComboBox();
                    comboBox.ItemTemplate = (DataTemplate)GetValue(ComboBoxItemTemplateProperty);
                    ComboBoxAttachedProps.SetSelectionBoxItemTemplate(comboBox, (DataTemplate)GetValue(ComboBoxSelectionBoxItemTemplateProperty));
                    var binding = new Binding("InstructionOperandVM.OperandListVM.Items") {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, binding);
                    binding = new Binding("InstructionOperandVM.OperandListVM.SelectedIndex") {
                        Source = this,
                        ValidatesOnDataErrors = true,
                        ValidatesOnExceptions = true,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    };
                    comboBox.SetBinding(ComboBox.SelectedIndexProperty, binding);
                    binding = new Binding("ComboBoxStyle") {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.StyleProperty, binding);
                    binding = new Binding("ComboBoxItemTemplate") {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBox.ItemTemplateProperty, binding);
                    binding = new Binding("ComboBoxSelectionBoxItemTemplate") {
                        Source = this,
                    };
                    comboBox.SetBinding(ComboBoxAttachedProps.SelectionBoxItemTemplateProperty, binding);
                    Content = comboBox;
                }
                break;

            default: throw new InvalidOperationException();
            }
        }