/// <summary>
        /// Handles changes to the IsEnabled property.
        /// </summary>
        /// <param name="d">
        /// The <see cref="DependencyObject"/> on which
        /// the property has changed value.
        /// </param>
        /// <param name="e">
        /// Event data that is issued by any event that
        /// tracks changes to the effective value of this property.
        /// </param>
        private static async void OnIsEnabledChanged(
            DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            bool oldIsEnabled = (bool)e.OldValue;
            bool newIsEnabled = (bool)d.GetValue(IsEnabledProperty);

            if (!d.IsInVisualTree())
                await ((FrameworkElement)d).WaitForLoadedAsync();

            var listBoxItem =
                d as ListBoxItem ??
                d.GetAncestors().OfType<ListBoxItem>().FirstOrDefault();
            if (listBoxItem == null)
                return;
            //throw new InvalidOperationException("ListBoxItemExtensions.IsEnabled can only be set on a ListBoxItem or its descendant in the visual tree");

            listBoxItem.IsEnabled = newIsEnabled;
        }