How to get information after the button licked?

Feb 28 at 12:59 PM
Edited Feb 28 at 1:01 PM
Hi,
I'm writing an interactive UI to let user select the course ID interested by binary plug-in. But the result seems like it will execute MessageBox.Show first then execute the WPF. How can I get the course ID after user clicking the select botton? Thanks.

cs file
using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Collections.Generic;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;


namespace VMS.TPS
{
  public class Script
  {
    public Script()
    {
    }


    public void Execute(ScriptContext context, System.Windows.Window window)
    {
      // TODO : Add here your code that is called when the script is launched from Eclipse

        var mainControl = new listboxGUI.GUI(context);
        window.Content = mainControl;
        MessageBox.Show(mainControl.cid);
    }
  }
}
xaml file
<UserControl x:Class="listboxGUI.GUI"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Height="266" Width="307">
    <DockPanel Width="277" Height="221">
        <StackPanel Orientation="Vertical" DockPanel.Dock="Top" Margin="10 10 10 3" Width="235">
            <TextBlock Height="19" Width="236">Course ID select:</TextBlock>
        </StackPanel>
        <DockPanel DockPanel.Dock="Bottom" Margin="10 0 10 10">
            <StackPanel Orientation="Horizontal">
                <Button Name="CourseButton" Height="22.725" Width="90" Margin="80 0 6 0" Click="CourseID_Click">Select</Button>
            </StackPanel>
        </DockPanel>
        <ListBox Name="SelCourseId" Margin="10 0 10 10" ItemsSource="{Binding Path=ItemList}" Height="142" Width="234" />
    </DockPanel>
</UserControl>
xaml.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using VMS.TPS.Common.Model.API;

namespace listboxGUI
{
    /// <summary>
    /// Interaction logic for GUI.xaml
    /// </summary>
    public partial class GUI : UserControl
    {
    
        private string _lastFolder = string.Empty;
        private ObservableCollection<string> _itemList = new ObservableCollection<string>();
        
        public ObservableCollection<string> ItemList {
            get { return _itemList ?? (_itemList = new ObservableCollection<string>()); }
            set { _itemList = value; }
        }
        
        public GUI(ScriptContext context)
        {
            InitializeComponent();
            foreach (Course cos in context.Patient.Courses)
            {
                ItemList.Add(cos.Id);
            }
            DataContext = this;
        }

        public string cid { get; set; }

        void CourseID_Click(object sender, RoutedEventArgs e)
        {

            string cid = SelCourseId.SelectedValue.ToString();
        }
    }
}
Mar 1 at 12:10 PM
It works when adding window.ShowDialog(); after window.Content = mainControl;
Coordinator
Mar 11 at 8:20 PM
The reason the message dialog box was shown before your window is that Eclipse displays your window after the Execute() method.