|
using System;
using System.Activities.Core.Presentation;
using System.Activities.Presentation;
using System.ComponentModel;
using System.IO;
using System.Windows.Input;
using System.Windows.Threading;
using RehostedDesigner.Designer.ViewModels.Contracts;
using RehostedDesigner.LoadErrorHandling;
namespace RehostedDesigner.Designer.ViewModels
{
public class StandardDesignerViewModel : INotifyPropertyChanged, IDesignerViewModel, ILoadErrorDesignerViewModel
{
private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;
public StandardDesignerViewModel()
{
this.CurrentSurface = new EmptyDesignerSurface();
}
public object CurrentSurface
{
get;
private set;
}
public event Action SurfaceChanged;
public event PropertyChangedEventHandler PropertyChanged;
public void ReloadError(string xaml)
{
this.CurrentSurface = new LoadErrorDesignerSurface(xaml);
this._dispatcher.Invoke(new Action(this.OnSurfaceChanged));
}
public void ReloadDesigner(object root)
{
WorkflowDesigner designer = null;
this._dispatcher.Invoke(new Action(() => designer = ReloadDesignerSTA(root)));
this.CurrentSurface = new StandardDesignerSurface(designer);
this._dispatcher.Invoke(new Action(this.OnSurfaceChanged));
}
private WorkflowDesigner ReloadDesignerSTA(object root)
{
var result = new WorkflowDesigner();
new DesignerMetadata().Register();
result.Load(root);
return result;
}
private void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
private void OnSurfaceChanged()
{
this.OnPropertyChanged("CurrentSurface");
if (this.SurfaceChanged != null)
{
this.SurfaceChanged();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.