public static void Save() { //Only writes if there's something changed. Should not write the default dictionary. if (_local == null && _appData == null) { return; } //Filename: Local or AppData. var filename = _local != null?Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.xaml") : Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ScreenToGif"), "Settings.xaml"); var backup = _local != null?Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.xaml.bak") : Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ScreenToGif"), "Settings.xaml.bak"); #region Create folder var folder = Path.GetDirectoryName(filename); if (!string.IsNullOrWhiteSpace(folder) && !Directory.Exists(folder)) { Directory.CreateDirectory(folder); } #endregion //Create backup. if (File.Exists(filename)) { File.Copy(filename, backup, true); } try { var settings = new XmlWriterSettings { Indent = true, CheckCharacters = true, CloseOutput = true, ConformanceLevel = ConformanceLevel.Fragment, Encoding = Encoding.UTF8, }; using (var writer = XmlWriter.Create(filename, settings)) XamlWriter.Save(_local ?? _appData, writer); if (File.ReadAllText(filename).All(x => x == '\0')) { File.Copy(backup, filename, true); } File.Delete(backup); } catch (Exception e) { LogWriter.Log(e, "Saving settings"); } }
public static void PrintGrid(ref DataGrid fwe, string header) { var columnWidths = GetColumnWidths(fwe); var ht = new HeaderTemplate(); var headerTemplate = XamlWriter.Save(ht); headerTemplate = headerTemplate.Replace("TitleHeader", header); var dt = Grid2Dt(fwe); var printControl = PrintControlFactory.Create(dt, columnWidths, headerTemplate); printControl.ShowPrintPreview(); // var visual = printControl.DrawingVisual; // SetUpPrint(fwe,visual); }
/// <summary> /// Saves data as XAML information. /// The output can then be used to serialize data. /// </summary> /// <param name="data">Data to write to file.</param> /// <param name="path">The file to which you want to write. /// Creates a file at the specified path and writes to it in XML 1.0 text syntax. /// The outputFileName must be a file system path.</param> /// /// <exception cref="ArgumentNullException">The url value is null or whitespace.</exception> /// <exception cref="ArgumentException">The path parameter contains invalid characters, is empty, or contains only white spaces.</exception> /// <exception cref="IOException">The network name is not known.</exception>\ /// <exception cref="UnauthorizedAccessException">The caller does not have the required permission to required directories.</exception> /// <exception cref="PathTooLongException"> /// The specified path exceed the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters /// and file names must be less than 260 characters.</exception> /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive).</exception> /// <exception cref="NotSupportedException">path contains a colon character (:) that is not part of a drive label ("C:\").</exception> /// <exception cref="SecurityException">The application is not running in full trust.</exception> public static void Save(object data, string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } var dir = Path.GetDirectoryName(path); Directory.CreateDirectory(dir); var settings = new XmlWriterSettings { Indent = true }; using (var writer = XmlWriter.Create(path, settings)) { XamlWriter.Save(data, writer); } }
public void Save() { var dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = true; var res = dialog.ShowDialog(); string dialogSelectedPath = null; if (res == System.Windows.Forms.DialogResult.OK) { dialogSelectedPath = dialog.SelectedPath; } if (dialogSelectedPath == null) { return; } var directoryName = Path.GetFileName(Path.GetDirectoryName(dialogSelectedPath)); var fs = File.Open(dialogSelectedPath + "\\" + directoryName + "_ink.xaml", FileMode.Create); XamlWriter.Save(DrawingSheet, fs); fs.Close(); DrawingSheet.UpdateLayout(); SaveChild(dialogSelectedPath, directoryName); }