public AppWindow(MyFlightSimulatorModel model, MainWindow main, IVM vm)
        {
            InitializeComponent();

            // initializing the main wondow fields and the vm field
            this._main = main;
            this.vm    = vm;

            // creating the view model of the dashboard
            DashboardVM dashboardVM = new DashboardVM(model);

            myDashboard.DataContext = dashboardVM;

            // creating the view model of the map
            MapVM mapVM = new MapVM(model);

            myMap.DataContext = mapVM;

            // creating the view model of the joystick
            JoystickVM joystickVm = new JoystickVM(model);

            myControlPlane.DataContext            = joystickVm;
            myControlPlane.myJoystick.DataContext = joystickVm;

            // creating the view model of the dashboard errors
            myDashboardErrors.DataContext = dashboardVM;
        }
Example #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Initialize the model.
            MyFlightSimulatorModel model = new MyFlightSimulatorModel();

            // Initialize the main view model.
            MainViewModel = new MainVM(model);
        }
        public MainWindow()
        {
            InitializeComponent();
            flightSimulatorModel = new MyFlightSimulatorModel(new MyTelnetClient());

            dataDisplayViewModel             = new DataDisplayViewModel(flightSimulatorModel);
            dataDisplayControl.DataDisplayVM = dataDisplayViewModel;

            graphViewModel       = new GraphViewModel(flightSimulatorModel);
            graphControl.GraphVM = graphViewModel;

            joystickViewModel          = new JoystickViewModel(flightSimulatorModel);
            joystickControl.JoystickVM = joystickViewModel;

            mediaViewModel            = new MediaViewModel(flightSimulatorModel);
            mediaPanelControl.MediaVM = mediaViewModel;

            startMenuViewModel           = new StartMenuViewModel(flightSimulatorModel);
            startMenuControl.StartMenuVM = startMenuViewModel;
        }
        /*
         * The cconection button - responsible for connecting properly, and showing the right windows.
         */
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // connection
            MyTelnetClient         telnetCli = new MyTelnetClient();
            MyFlightSimulatorModel model     = new MyFlightSimulatorModel(telnetCli);

            this.vm = new ConnectionViewModel(model);

            // bind the error light to the vm
            this.errorLight.DataContext = new DashboardVM(model);

            // get the ip and port from the textbox
            string ip   = this.IPTextbox.Text;
            string port = this.PortTextbox.Text;

            try
            {
                // converting the port from string to int
                int intPort = int.Parse(port);

                // connecting to the server
                int isSucceed = this.vm.model.connect(ip, intPort);
                if (isSucceed == 1)
                {
                    this.vm.model.start();
                    this.vm.model.startQueue();
                    AppWindow app = new AppWindow(model, this, this.vm);
                    app.Show();
                    this.Hide();
                }
            }
            catch
            {
                this.vm.model.ConnectionError = "Blue";
            }
        }