using Syncfusion.Windows.PropertyGrid;
using Syncfusion.Windows.Shared;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SFMVVM.Views
{
    /// <summary>
    /// Interaction logic for PropertyGridView.xaml
    /// </summary>
    public partial class PropertyGridView : UserControl
    {
        public PropertyGridView()
        {
            InitializeComponent();
            this.ContactDetailPropertyGrid.Loaded += PropertyGrid_Loaded;
        }

        private void PropertyGrid_Loaded(object sender, RoutedEventArgs e)
        {
            PropertyView item1 = VisualUtils.FindDescendant(this, typeof(PropertyView)) as PropertyView;

            if (item1 != null)
            {
                item1.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
            }

        }

        void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
        {
            foreach (PropertyCatagoryViewItem item in VisualUtils.EnumChildrenOfType(this, typeof(PropertyCatagoryViewItem)))
            {
                foreach (var items in item.Items)
                {
                    foreach (PropertyViewItem propertyviewitem in VisualUtils.EnumChildrenOfType(this, typeof(PropertyViewItem)))
                    {
                        ToggleButton button = (ToggleButton)propertyviewitem.Template.FindName("ToggleButton", propertyviewitem);
                        if (button.Visibility == System.Windows.Visibility.Visible && !button.IsMouseOver)
                        {
                            button.IsChecked = true;
                        }
                    }

                }
            }
        }

    }
}
