Beispiel #1
0
        private void OnAddImageClicked(object sender, RoutedEventArgs e)
        {
            string result;

            if (sender == AddImageLocalButton)
            {
                var ofd = SelectImage(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
                if (ofd.FileName == null)
                {
                    return;
                }

                result = ofd.FileName;
            }
            else if (sender == AddImageOnlineButton)
            {
                //var vm = new SimpleInputViewModel("Enter file URL:", "Add Image");
                //var view = ViewFactory.CreateViewWithDataContext<SimpleInputView>(vm);
                //view.ShowDialog();
                var vm = InputViewFactory.ShowTextBoxInput("Enter file URL:", "Add Image");
                if (vm.UserCancelled)
                {
                    return;
                }

                result = vm.SelectedValue;
            }
            else
            {
                var ofd = SelectImage(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
                if (ofd == null)
                {
                    return;
                }

                var vm = DataContext as EditOmniViewModel;
                if (vm == null)
                {
                    return;
                }

                var imageDesc = vm.EmbedImage(ofd.FileName, ofd.SafeFileName).Replace(" ", "%20");

                SurroundDescriptionTextWith("![", $@"](dbfile:///{imageDesc})", "image description");
                return;
            }

            try
            {
                var uri = new Uri(result);
                SurroundDescriptionTextWith("![", $"]({uri.AbsoluteUri})", "image description");
            }
            catch (UriFormatException)
            {
                SurroundDescriptionTextWith("![", $"]({result})", "image alt text");
            }
        }