私の問題は、GeometryModel3DのMaterialがXAMLのStaticResourceから設定されている次のプログラムに表示されます。XamlWriterにStaticResourceを保存させることは可能ですか?
解決済みの参照ではなく実際のStaticResourcesを保存するようにXamlWriterを設定することはできますか?もしそうなら、私は何をする必要がありますか?
using System;
using System.IO;
using System.Text;
using System.Windows.Controls;
using System.Windows.Markup;
namespace MaterialTest
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string xaml = "";
xaml += "<Viewport3D xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>";
xaml += " <Viewport3D.Resources>";
xaml += " <DiffuseMaterial x:Key='Steel' />";
xaml += " </Viewport3D.Resources>";
xaml += " <ModelVisual3D>";
xaml += " <ModelVisual3D.Content>";
xaml += " <GeometryModel3D Material='{StaticResource Steel}'>";
xaml += " <GeometryModel3D.Geometry>";
xaml += " <MeshGeometry3D Positions='-0.5,-0.5,0 0.5,-0.5,0 0.5,0.5,0 -0.5,0.5,0' TriangleIndices='0 1 2 0 2 3' />";
xaml += " </GeometryModel3D.Geometry>";
xaml += " </GeometryModel3D>";
xaml += " </ModelVisual3D.Content>";
xaml += " </ModelVisual3D>";
xaml += "</Viewport3D>";
MemoryStream buffer = new MemoryStream(Encoding.UTF8.GetBytes(xaml));
Viewport3D viewport = XamlReader.Load(buffer) as Viewport3D;
string xaml_out = XamlWriter.Save(viewport);
}
}
}
ありがとうございます。私は、XamlWriterが静的リソースを書き出すのを容易にするいくつかの高度な機能があることを期待していました。私は、標準のXamlWriterが静的リソースの書き込みを管理することができないと信じているとは思えません。 私のアプローチは、XamlWriterでXamlを作成し、Xmlパーサーで後処理ステップで静的リソースを管理することです。 –