Exemplo n.º 1
0
        private void PickTextureButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Multiselect = false, Filter = "Png Images | *.png"
            };
            string newFilePath = "";

            NonTopMostPopup.IsOpenedByDialog = true;
            if (ofd.ShowDialog().GetValueOrDefault())
            {
                string directory   = TexturePickerViewModel.GetTextureImagesFolder();
                string newFileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(ofd.FileName);
                newFilePath = Path.Combine(directory, newFileName);
                try
                {
                    File.Copy(ofd.FileName, newFilePath, true);

                    BitmapImage imageSource = new BitmapImage();
                    imageSource.BeginInit();
                    imageSource.UriSource = new Uri("file://" + newFilePath);
                    imageSource.EndInit();

                    ImageBrush brush = new ImageBrush(imageSource);
                    brush.SetValue(Canvas.TagProperty, newFilePath);
                    textureColorPicker.ImageBrushes.Add(brush);

                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        ((Popup)((FrameworkElement)this.Parent)).IsOpen = true;
                        e.Handled = true;
                    }));
                }
                catch (IOException ex)
                {
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                    System.Windows.Forms.MessageBox.Show(ex.Message, "IOException");
                }
                catch (Exception ex)
                {
                    string originalExceptionMessage = ex.Message;
                    string newExceptionMessage      = Regex.IsMatch(originalExceptionMessage, accessDeniedPattern) ?
                                                      string.Format(CultureInfo.InvariantCulture, accessDeniedMessageFormat, newFilePath) : originalExceptionMessage;
                    System.Windows.Forms.MessageBox.Show(newExceptionMessage, "Warning");
                }
            }
        }
Exemplo n.º 2
0
 public TexturePicker()
 {
     InitializeComponent();
     viewModel   = new TexturePickerViewModel();
     DataContext = viewModel;
 }