I have a program where the user can view various 3Dmodels which are saved in XAML and then manipulate the Viewport3D using a TrackballDecorator. Included in these XAML files are transforms which I was applying to the TrackballDecorator using the modifications in the answer to the question WPF 3D - How can I save and load a Camera view?
I recently switched the project to the .net 4.5 framework to take advantage of the new async functionality of the XamlReader class and it has caused a conflict with the way I'm accessing the transforms saved with the models.
What I am currently doing is:
private Task<TrackballDecorator> loadModel(string path)
{
var tempVP = new XamlReader().LoadAsync(XmlReader.Create(path)) as Viewport3D;
return new TrackballDecorator() { Content = tempVP, Transform = (tempVP.Camera.Transform as Transform3DGroup) };
}
This doesn't work, as the XamlReader isn't finished loading so a null Transform is returned.
What I would like to do is:
private async Task<TrackballDecorator> loadModelAsync(string path)
{
var tempVP = await new XamlReader().LoadAsync(XmlReader.Create(path)) as Viewport3D;
return new TrackballDecorator() { Content = tempVP, Transform = (tempVP.Camera.Transform as Transform3DGroup) };
}
But because the LoadAsync method returns an object
and not a Task<object>
I cannot use the await keyword. Is there any way to overcome or work around this limitation?