private void BtnImport_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.Filter = "Text files (*.xml)|*.txt|All files (*.*)|*.*"; openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == true) { XmlSerializer serializer = new XmlSerializer(typeof(XenaxStageGUIControlVM)); // A FileStream is needed to read the XML document. FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open); /* Use the Deserialize method to restore the object's state with * data from the XML document. */ handle = (XenaxStageGUIControlVM)serializer.Deserialize(fs); } } catch { } }
public MainWindow() { InitializeComponent(); //this.Title += string.Format(" v{0}.{1}.{2}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build); if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) { this.Title += "ver " + System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.Major.ToString() + "." + System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.Revision.ToString(); } handle = this.DataContext as XenaxStageGUIControlVM; DebounceTimer.Interval = TimeSpan.FromMilliseconds(50); crosshairWindow.handle = handle; handle.xenaxDeviceConnectionsVM = xenax1.xenaxDeviceConnections; this.dgConnections.DataContext = xenax1.xenaxDeviceConnections; //Add additional handler to sliders object wantedNode = this.FindName("slManualRotation"); if (wantedNode is Slider) { // Following executed if Text element was found. Slider wantedChild = wantedNode as Slider; wantedChild.AddHandler(PreviewMouseUpEvent, new RoutedEventHandler(SlManualRotation_MouseUp), true); wantedChild.AddHandler(PreviewMouseDownEvent, new RoutedEventHandler(SlManualRotation_MouseDown), true); wantedChild.AddHandler(MouseLeaveEvent, new RoutedEventHandler(SlManualRotation_MouseLeave), true); wantedChild.AddHandler(Slider.ValueChangedEvent, new RoutedEventHandler(SlManualRotation_ValueChanged), true); wantedChild.AddHandler(Slider.DragLeaveEvent, new DragEventHandler(SlManualRotation_DragLeave), true); } object wantedNode2 = this.FindName("slPositionLin"); if (wantedNode is Slider) { // Following executed if Text element was found. Slider wantedChild = wantedNode2 as Slider; wantedChild.AddHandler(PreviewMouseDownEvent, new RoutedEventHandler(SlPositionLin_MouseDown), true); } xenax1.ConnectionUpdate += Xenax_ConnectionUpdate; xenax1.MotorStatusUpdate += Xenax1_MotorStatusUpdate; xenax1.PositionVelocityUpdated += Xenax_PositionSpeedAccUpdated; xenax1.PositionReached += Xenax_PositionReached; xenax1.DataReceived += Xenax1_DataReceived; xenax1.DataSent += Xenax1_DataSent; currentPositionTimer.Tick += CurrentPositionTimer_Tick; currentPositionTimer.Interval = TimeSpan.FromMilliseconds(250); }