using System.Windows.Controls;
using JeffWilcox.Samples;
using System.Windows;
using System.Windows.Interactivity;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.Windows.Data;

namespace DateTimeFiltering
{
    public class CellValueBindingBehavior : LoadBehavior<FrameworkElement>
    {
        protected override void OnAssociatedObjectLoaded()
        {
            base.OnAssociatedObjectLoaded();

            var cell = this.AssociatedObject.ParentOfType<GridViewCell>();
            if (cell != null)
            {
                this.AssociatedObject.SetBinding(HighlightingTextBlock.TextProperty, new Binding("Value") { Source = cell, Mode = BindingMode.TwoWay });
            }
        }

        protected override void OnDetaching()
        {
            this.AssociatedObject.ClearValue(HighlightingTextBlock.TextProperty);

            base.OnDetaching();
        }
    }
}