Esempio n. 1
0
        private Control[] FilePickerControls(LaunchDialogViewModel viewModel, string label,
                                             Expression <Func <LaunchDialogViewModel, string> > propertyExpression)
        {
            var pickLabel = new Label()
            {
                Text = label, VerticalAlignment = VerticalAlignment.Center
            };
            var fileTextBox = new TextBox()
            {
                Width = 300
            };

            fileTextBox.TextBinding.BindDataContext <LaunchDialogViewModel>(propertyExpression);
            var filePicker = new Button()
            {
                Text = "...", Width = 30
            };

            filePicker.Click += (s, a) =>
            {
                var dialog = new OpenFileDialog();
                var result = dialog.ShowDialog(this);
                if (result == DialogResult.Ok)
                {
                    ReflectionUtils.SetProperty(viewModel, dialog.FileName, propertyExpression);
                }
            };

            return(new Control[] { pickLabel, fileTextBox, filePicker });
        }
Esempio n. 2
0
        public LaunchDialog(LaunchDialogViewModel viewModel)
        {
            var layout = new DynamicLayout
            {
                DefaultSpacing = new Size(20, 10),
                Padding        = new Padding(20, 10)
            };

            // Row 1: Boot ROM File Picker
            layout.AddRow(FilePickerControls(viewModel, "Pick boot ROM:", vm => vm.BootromFile));

            // Row 2: ROM File Picker
            layout.AddRow(FilePickerControls(viewModel, "Pick ROM:", vm => vm.RomFile));

            // Row 3: Launch button
            var launchButton = new Button()
            {
                Text = "Launch"
            };

            launchButton.Click += (s, a) => OnLaunchClick(viewModel);

            layout.AddRow(launchButton);

            Content     = layout;
            DataContext = viewModel;
        }
Esempio n. 3
0
 private void OnLaunchClick(LaunchDialogViewModel viewModel)
 {
     Close(new LaunchDialogResult
     {
         BootromFile = viewModel.BootromFile,
         RomFile     = viewModel.RomFile
     });
 }