示例#1
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Button:");
            System.Console.WriteLine();

            AbstractButton steelButton = ControlFactory.GetButton(ControlFactory.ButtonType.Steel);

            steelButton.OnClick();

            AbstractButton rubberButton = ControlFactory.GetButton(ControlFactory.ButtonType.Rubber);

            rubberButton.OnClick();

            System.Console.WriteLine();
            System.Console.WriteLine("Text Box:");
            System.Console.WriteLine();

            AbstractTextBox steelTextBox = ControlFactory.GetTextBox(ControlFactory.TextBoxType.Steel);

            steelTextBox.Show();

            AbstractTextBox rubberTextBox = ControlFactory.GetTextBox(ControlFactory.TextBoxType.Rubber);

            rubberTextBox.Show();

            AbstractTextBox woodTextBox = ControlFactory.GetTextBox(ControlFactory.TextBoxType.Wood);

            woodTextBox.Show();

            System.Console.WriteLine();
        }
        /// <inheritdoc />
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value is AbstractUIViewModelBase)
            {
                return(value);
            }

            return(value switch
            {
                AbstractTextBox textBox => new AbstractTextBoxViewModel(textBox),
                AbstractDataList dataList => new AbstractDataListViewModel(dataList),
                AbstractButton button => new AbstractButtonViewModel(button),
                AbstractBoolean boolean => new AbstractBooleanViewModel(boolean),
                AbstractRichTextBlock richText => new AbstractRichTextBlockViewModel(richText),
                AbstractMultiChoice multiChoiceUIElement => new AbstractMultiChoiceViewModel(multiChoiceUIElement),
                AbstractForm form => new AbstractFormViewModel(form),
                AbstractUICollection elementGroup => new AbstractUICollectionViewModel(elementGroup),
                AbstractProgressIndicator progress => new AbstractProgressIndicatorViewModel(progress),
                AbstractColorPicker color => new AbstractColorPickerViewModel(color),

                _ => throw new NotSupportedException($"No match ViewModel was found for {value.GetType()}."),
            });