using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Controls; namespace HeuristicLab.MainForm.WPF { public abstract class WPFView : UserControl, IView { private string caption = "WPF View"; public string Caption { get { return caption; } set { if (value == caption) return; if (value == null) throw new ArgumentNullException("View caption cannot be null"); caption = value; OnCaptionChanged(); } } public event EventHandler CaptionChanged; protected void OnCaptionChanged() { EventHandler handler = CaptionChanged; if (handler != null) handler(this, EventArgs.Empty); } public event EventHandler Changed; protected void OnChanged() { EventHandler handler = Changed; if (handler != null) handler(this, EventArgs.Empty); } public virtual void Close() { MainFormManager.GetMainForm().CloseView(this); IsShown = false; } public void Hide() { MainFormManager.GetMainForm().HideView(this); IsShown = false; } public bool IsShown { get; protected set; } private bool readOnly = false; public bool ReadOnly { get { return readOnly; } set { if (value == readOnly) return; readOnly = value; OnReadOnlyChanged(); } } public event EventHandler ReadOnlyChanged; protected void OnReadOnlyChanged() { EventHandler handler = ReadOnlyChanged; if (handler != null) handler(this, EventArgs.Empty); } protected abstract void OnFirstTimeShown(); public void Show() { if (MainFormManager.GetMainForm().ShowView(this)) OnFirstTimeShown(); IsShown = true; } } }