示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XamlWriter"/> class.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="settings">The settings.</param>
 public XamlWriter(XmlWriter writer, XamlWriterSettings settings)
 {
     if (writer == null) {
         throw new ArgumentNullException("writer");
     }
     if (settings == null) {
         throw new ArgumentNullException("settings");
     }
     this.writer = writer;
     this.settings = settings;
 }
示例#2
0
        /// <summary>
        /// Gets the XAML of specified framework element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public static string Save(FrameworkElement element, XamlWriterSettings settings)
        {
            if (element == null) {
                throw new ArgumentNullException("element");
            }

            StringBuilder output = new StringBuilder();

            try {
                using (XamlWriter writer = CreateWriter(output, false, settings)) {
                    writer.WriteElement(element);
                }
            }
            catch (Exception e) {
                WriteException(output, e);
            }

            return output.ToString();
        }
示例#3
0
        /// <summary>
        /// Creates a XAML writer for given output and settings.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <param name="newLineOnAttributes">whether to write attributes on a new line.</param>
        /// <param name="settings">The settings.</param>
        /// <returns></returns>
        public static XamlWriter CreateWriter(StringBuilder output, bool newLineOnAttributes, XamlWriterSettings settings)
        {
            XmlWriterSettings xmlSettings = new XmlWriterSettings();
            xmlSettings.Indent = true;
            xmlSettings.NewLineOnAttributes = newLineOnAttributes;
            xmlSettings.ConformanceLevel = ConformanceLevel.Fragment;

            XmlWriter writer = XmlWriter.Create(output, xmlSettings);

            return new XamlWriter(writer, settings);
        }