using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace CustomFilterEditor
{
    public class MyGuidColumn : GridViewBoundColumnBase
    {
        public override FrameworkElement CreateFieldFilterEditor()
        {
            // Use the factory to produce an editor, but you can do it yourself if you want
            // You already saw the code that is inside the factory class.
            var textBox = (TextBox)FilterEditorFactory.CreateDefaultEditor();

            // "Value" is the name of the property on our ViewModel sitting behind the editor.
            // You should always bind your custom filter editor to the "Value" property of our ViewModel.
            // The StringFilterEditor does this in its XAML, that is why you could not see it :)
            var textBinding = new Binding("Value")
            {
                Mode = BindingMode.TwoWay,
                FallbackValue = null,
                Converter = new GuidConverter() // --> this the key point
            };

            // We will overwrite the default binding with a new one that uses the converter.
            textBox.SetBinding(TextBox.TextProperty, textBinding);

            return textBox;
        }
    }
}
