Exemplo n.º 1
0
        /// <summary>
        /// Load embedded example
        /// </summary>
        /// <param name="name">Example file name</param>
        public void LoadExample(string name)
        {
            try
            {
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_model.GetType());
                using (System.Xml.XmlReader reader = new System.Xml.XmlTextReader(System.Windows.Application.GetResourceStream(new System.Uri("/examples/" + name, UriKind.Relative)).Stream))
                {
                    if (x.CanDeserialize(reader))
                        _model = x.Deserialize(reader) as SettingsModel;
                    reader.Close();
                }

                // update all properties
                InvokePropertyChanged(null);
            }
            catch
            {
                System.Windows.MessageBox.Show("Couldn't load L-System, please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public MainWindowViewModel()
 {
     _renderer = new Renderer();
     _model = new SettingsModel();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Load L-System definition file
        /// </summary>
        public void LoadDefinition()
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".ls"; // Default file extension
            dlg.Filter = "L-System files(*.ls)|*.ls|All files (*.*)|*.*"; // Filter files by extension

            // Show save file dialog box
            bool? result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Load document
                string filename = dlg.FileName;
                try
                {
                    System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_model.GetType());
                    using (System.Xml.XmlReader reader = new System.Xml.XmlTextReader(filename))
                    {
                        if (x.CanDeserialize(reader))
                            _model = x.Deserialize(reader) as SettingsModel;
                        reader.Close();
                    }
                }
                catch
                {
                    System.Windows.MessageBox.Show("Couldn't load L-System, please try again later.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                }
            }

            // update all properties
            InvokePropertyChanged(null);
        }