I'm looking over th开发者_如何学运维e MSDN documentation for the System.Xaml namespace and in particular the XamlServices class. I'm wondering what a use case for the XamlServices.Transform method would be?
I've got nothing against it, I just don't see a case where this would be useful and I'm wondering what I'm missing.
The Transform takes a XamlReader and a XamlWriter.
There are two out-of-the-box writers and there are five out-of-the-box readers. Of course you can create your own.
So the Transform method allows you to stitch one of the readers and one of the writers together to transfer/translate/transform the xaml from one place to another.
There are a couple of scenarios when loose Xaml is useful but to me the most obvious two are:
- Workflow definitions and
- Design-time/run-time generators of UI
EDIT
This is the code from the Transform method:
public static void Transform(XamlReader xamlReader, XamlWriter xamlWriter, bool closeWriter)
{
if (xamlReader == null)
throw new ArgumentNullException("xamlReader");
if (xamlWriter == null)
throw new ArgumentNullException("xamlWriter");
IXamlLineInfo xamlLineInfo = xamlReader as IXamlLineInfo;
IXamlLineInfoConsumer lineInfoConsumer = xamlWriter as IXamlLineInfoConsumer;
bool flag = false;
if (xamlLineInfo != null && xamlLineInfo.HasLineInfo && (lineInfoConsumer != null && lineInfoConsumer.ShouldProvideLineInfo))
flag = true;
while (xamlReader.Read())
{
if (flag && xamlLineInfo.LineNumber != 0)
lineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber,xamlLineInfo.LinePosition);
xamlWriter.WriteNode(xamlReader);
}
if (!closeWriter)
return;
xamlWriter.Close();
}
Nothing fancy but just convenient so you do not have to write it yourself.
精彩评论