using System;
using System.Windows;
using System.Windows.Controls;
using System35;
using JetBrains.Omea.OpenAPI;
namespace JetBrains.UI.Avalon
{
///
/// A border-derived control that supports runtime delegate-based data templates.
/// On creation, exeutes the supplied code to build the nested objects.
///
public class TemplateBorder : Decorator
{
#region Data
public static readonly DependencyProperty ObjectGraphCreatorProperty = DependencyProperty.Register("ObjectGraphCreator", typeof(Func), typeof(TemplateBorder), new PropertyMetadata(OnObjectGraphCreatorPropertyChanged));
#endregion
#region Implementation
private static void OnObjectGraphCreatorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
((TemplateBorder)d).ApplyObjectGraphCreatorProperty((Func)args.NewValue);
}
///
/// Creates the new object graph whenever changes its value.
///
private void ApplyObjectGraphCreatorProperty(Func value)
{
try
{
Child = value != null ? value() : null;
}
catch(Exception ex)
{
Core.ReportException(new InvalidOperationException(string.Format("Could not create the object graph. {0}", ex.Message), ex));
}
}
#endregion
}
}