/// <summary>
        /// Creates a combo box with data binding.
        /// </summary>
        /// <param name="d">The cell definition.</param>
        /// <returns>
        /// A ComboBox.
        /// </returns>
        protected virtual FrameworkElement CreateComboBox(SelectorCellDefinition d)
        {
            var c = new ComboBox
            {
                IsEditable = d.IsEditable,
                Focusable  = false, // keep focus on the data grid until the user opens the dropdown
                Margin     = new Thickness(1, 1, 0, 0),
                HorizontalContentAlignment = d.HorizontalAlignment,
                VerticalContentAlignment   = VerticalAlignment.Center,
                Padding         = new Thickness(3, 0, 3, 0),
                BorderThickness = new Thickness(0)
            };

            if (d.ItemsSource != null)
            {
                c.ItemsSource = d.ItemsSource;
            }
            else
            {
                if (d.ItemsSourceProperty != null)
                {
                    var itemsSourceBinding = new Binding(d.ItemsSourceProperty);
                    c.SetBinding(ItemsControl.ItemsSourceProperty, itemsSourceBinding);
                }
            }

            c.DropDownOpened += (s, e) =>
            {
                // when the dropdown has been opened by F4 or mouse down
                // it should be possible to change selection by the arrow keys
                // or edit the text (if the property is annotated as editable)
                c.Focusable = true;
            };

            c.DropDownClosed += (s, e) =>
            {
                // when the dropdown has been closed
                // the arrows keys should be used to change cell
                // the (undesired) side effect is also that the text cannot be edited (if the property is annotated as editable)
                c.Focusable = false;

                FocusParentDataGrid(c);
            };

            var binding = this.CreateBinding(d);

            binding.NotifyOnSourceUpdated = true;
            c.SetBinding(d.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, binding);
            c.SelectedValuePath = d.SelectedValuePath;
            c.DisplayMemberPath = d.DisplayMemberPath;
            this.SetIsEnabledBinding(d, c);
            this.SetBackgroundBinding(d, c);
            return(c);
        }
        /// <summary>
        /// Creates a text block control for a selector cell.
        /// </summary>
        /// <param name="d">The cell definition.</param>
        /// <returns>
        /// A TextBlock.
        /// </returns>
        protected virtual FrameworkElement CreateTextBlockControl(SelectorCellDefinition d)
        {
            var c = new TextBlockEx
            {
                HorizontalAlignment = d.HorizontalAlignment,
                VerticalAlignment   = VerticalAlignment.Center,
                Padding             = new Thickness(4, 0, 4, 0)
            };

            var binding = this.CreateOneWayBinding(d);

            if (!string.IsNullOrEmpty(d.DisplayMemberPath) && string.IsNullOrEmpty(d.SelectedValuePath))
            {
                binding.Path.Path += "." + d.DisplayMemberPath;
            }

            c.SetBinding(TextBlock.TextProperty, binding);
            this.SetIsEnabledBinding(d, c);

            return(this.CreateContainer(d, c));
        }