<commit_before>namespace Caliburn.PresentationFramework.Conventions
{
    using System;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Data;
    using Core;
    using ViewModels;

    /// <summary>
    /// An implemenation of <see cref="IViewConvention{T}"/> that bindings SelectedItem and Header for Selectors and HeaderedItemsControls respectively.
    /// ItemsTemplates may be conventionally added as well.
    /// </summary>
    public class ItemsControlBindingConvention : ViewConventionBase<PropertyInfo>
    {
        private static readonly Type _itemsControlType = typeof(ItemsControl);
        private static readonly Type _selectorControlType = typeof(Selector);

#if !SILVERLIGHT
        private static readonly Type _headeredItemsControlType = typeof(HeaderedItemsControl);
#endif
        /// <summary>
        /// Creates the application of the convention.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="element">The element.</param>
        /// <param name="property">The property.</param>
        /// <returns>The convention application.</returns>
        public override IViewApplicable TryCreateApplication(IViewModelDescription description, IElementDescription element, PropertyInfo property)
        {
            var originalPath = DeterminePropertyPath(element.Name);
            var boundProperty = GetBoundProperty(property, originalPath);

            if (boundProperty == null || !_itemsControlType.IsAssignableFrom(element.Type))
                return null;

            string path;
            DependencyProperty bindableProperty;
            BindingMode mode;

            if (_selectorControlType.IsAssignableFrom(element.Type))
            {
                string selectionPath;
                PropertyInfo selectionProperty;

                if (TryGetByPattern(property, originalPath, out selectionPath, out selectionProperty,
                    originalName => originalName.MakeSingular(),
                    (info, baseName) =>
                        info.Name == "Current" + baseName ||
                        info.Name == "Active" + baseName ||
                        info.Name == "Selected" + baseName)
                    )
                {
                    path = selectionPath;
                    bindableProperty = Selector.SelectedItemProperty;
                    mode = selectionProperty.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay;
                }
                else return null;
            }
#if !SILVERLIGHT
            else if (_headeredItemsControlType.IsAssignableFrom(element.Type))
            {
                string headerPath;
                PropertyInfo headerProperty;

                if (TryGetByPattern(property, originalPath, out headerPath, out headerProperty,
                    originalName => originalName,
                    (info, baseName) =>
                        info.Name == baseName + "Header")
                    )
                {
                    path = headerPath;
                    bindableProperty = HeaderedItemsControl.HeaderProperty;
                    mode = headerProperty.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay;
                }
                else return null;
            }
#endif
            else return null;

            return new ApplicableBinding(
                element.Name,
                bindableProperty,
                path,
                mode,
                false,
                true
                );
        }
    }
}<commit_msg>Fixed a bug in ItemsControlBindingConvention.<commit_after>namespace Caliburn.PresentationFramework.Conventions
{
    using System;
    using System.Reflection;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Data;
    using Core;
    using ViewModels;

    /// <summary>
    /// An implemenation of <see cref="IViewConvention{T}"/> that bindings SelectedItem and Header for Selectors and HeaderedItemsControls respectively.
    /// ItemsTemplates may be conventionally added as well.
    /// </summary>
    public class ItemsControlBindingConvention : ViewConventionBase<PropertyInfo>
    {
        private static readonly Type _itemsControlType = typeof(ItemsControl);
        private static readonly Type _selectorControlType = typeof(Selector);

#if !SILVERLIGHT
        private static readonly Type _headeredItemsControlType = typeof(HeaderedItemsControl);
#endif
        /// <summary>
        /// Creates the application of the convention.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="element">The element.</param>
        /// <param name="property">The property.</param>
        /// <returns>The convention application.</returns>
        public override IViewApplicable TryCreateApplication(IViewModelDescription description, IElementDescription element, PropertyInfo property)
        {
            var originalPath = DeterminePropertyPath(element.Name);
            var boundProperty = GetBoundProperty(property, originalPath);

            if (boundProperty == null || !_itemsControlType.IsAssignableFrom(element.Type))
                return null;

            string path = null;
            DependencyProperty bindableProperty = null;
            BindingMode mode = BindingMode.OneWay;

            if (_selectorControlType.IsAssignableFrom(element.Type))
            {
                string selectionPath;
                PropertyInfo selectionProperty;

                if (TryGetByPattern(property, originalPath, out selectionPath, out selectionProperty,
                    originalName => originalName.MakeSingular(),
                    (info, baseName) =>
                        info.Name == "Current" + baseName ||
                        info.Name == "Active" + baseName ||
                        info.Name == "Selected" + baseName)
                    )
                {
                    path = selectionPath;
                    bindableProperty = Selector.SelectedItemProperty;
                    mode = selectionProperty.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay;
                }
                else return null;
            }
#if !SILVERLIGHT
            else if (_headeredItemsControlType.IsAssignableFrom(element.Type))
            {
                string headerPath;
                PropertyInfo headerProperty;

                if (TryGetByPattern(property, originalPath, out headerPath, out headerProperty,
                    originalName => originalName,
                    (info, baseName) =>
                        info.Name == baseName + "Header")
                    )
                {
                    path = headerPath;
                    bindableProperty = HeaderedItemsControl.HeaderProperty;
                    mode = headerProperty.CanWrite ? BindingMode.TwoWay : BindingMode.OneWay;
                }
                else return null;
            }
#endif

            return new ApplicableBinding(
                element.Name,
                bindableProperty,
                path,
                mode,
                false,
                true
                );
        }
    }
}
{'fraction_non_alphanumeric': 0.07853757616790792, 'fraction_numerical': 0.0, 'mean_word_length': 1.7725225225225225, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3526327', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1617, 'n_words': 402}