简体   繁体   English

什么是WPF的DataFormats类中的UWP等效Xaml数据格式字段

[英]What is UWP equivalent of Xaml data format field in DataFormats class of WPF

I've been trying to find out a UWP equivalent of DataFormats Class in WPF that has Xaml as a data format field - or may be there is a workaround in UWP? 我一直在尝试在WPF中找到UWP等效的DataFormats类,它将Xaml作为数据格式字段 - 或者可能在UWP中有解决方法?

As shown in the link above, the Xaml is one of the data format in WPF's DataFormats class. 如上面的链接所示, Xaml是WPF的DataFormats类中的数据格式之一。 But so far I've not found such an equivalent in UWP. 但到目前为止,我还没有在UWP中找到这样的等价物。 The StandardDataFormats Class in UWP does not list Xaml as one of its Data Format. UWP中的StandardDataFormats类不会将Xaml列为其数据格式之一。

Motivation : 动机

Similar to the WPF example shown here: TextRange.Save method , I'm trying convert the following WPF code to a UWP code. 类似于此处显示的WPF示例: TextRange.Save方法 ,我正在尝试将以下WPF代码转换为UWP代码。 But as you can see on line range.Save(outputStream, DataFormats.Xaml); 但正如你可以在线上看到的range.Save(outputStream, DataFormats.Xaml); the WPF code is using Xaml as data format when saving the range selection to a memory stream: 将范围选择保存到内存流时,WPF代码使用Xaml作为数据格式:

....
var doc = new FlowDocument();
var range = new TextRange(doc.ContentStart, doc.ContentEnd);

using (var outputStream = new MemoryStream())
{
   range.Save(outputStream, DataFormats.Xaml);
   outputStream.Position = 0;
   using (var xamlStream = new StreamReader(outputStream))
   {
      var xaml = xamlStream.ReadToEnd();
      File.WriteAllText(xamlFileName, xaml);
   }
}

UWP's TextRange struct does not have a method named Save so your question is moot. UWP的TextRange结构没有名为Save的方法,所以你的问题没有实际意义。

To my knowledge, UWP does not (easily) support manipulating XAML markup at runtime (eg there is no XamlWriter class, and there is no API for the manipulating of XAML, though Windows.UI.Xaml.Markup.XamlReader and XmlBinaryWriter are available, they don't seem intended for use by application developers, but are meant for the build process). 据我所知,UWP不支持(轻松)支持在运行时操作XAML标记(例如,没有XamlWriter类,并且没有用于操作XAML的API,尽管Windows.UI.Xaml.Markup.XamlReaderXmlBinaryWriter可用,它们似乎不是供应用程序开发人员使用,而是用于构建过程)。

If you want to serialize a UWP TextRange in a way that maintains document structure I think you'll need to serialize (and deserialize) that yourself using some custom logic (though I wonder what happens if you pass your TextRange instance into JsonConvert.SerializeObject( ... ) ...). 如果你想以维护文档结构的方式序列化UWP TextRange ,我认为你需要使用一些自定义逻辑来自行序列化(和反序列化)(尽管我想知道如果将TextRange实例传递给JsonConvert.SerializeObject( ... )会发生什么JsonConvert.SerializeObject( ... ) ......)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM