Exemple #1
0
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            _painting = new Painting();

            statusText.Text = "Ready.";

            var rect = new CustomRectangle(30, 30, 100, 100, Brushes.Red, Brushes.Black, 3);
            _painting.Shapes.Add(rect);
            canvas.Children.Add(rect.Shape);
        }
Exemple #2
0
        private void Open()
        {
            HandleUnsavedChanges();

            // Create an OpenFileDialog.
            var dialog = new OpenFileDialog();

            // Show the dialog, abort if not successful
            if (dialog.ShowDialog() != true) return;

            _fileName = dialog.FileName;

            StreamReader streamReader = null;
            try
            {
                var xmlSerializer = new XmlSerializer(typeof(Painting));
                streamReader = new StreamReader(_fileName);
                _painting = (Painting)xmlSerializer.Deserialize(streamReader);
            }
            catch (XmlException xe)
            {
                MessageBox.Show(xe.Message, "XML Parse Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }
            catch (InvalidOperationException ioe)
            {
                MessageBox.Show(ioe.InnerException.Message, "XML Serialization Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }

            statusText.Text = String.Format("Painting opened ({0}).", _fileName);
        }