Beispiel #1
0
        private static void PreparePrepareHeaderedItemsControlContainer(HeaderedItemsControl control, object item, ItemsControl parentItemsControl, Style parentItemContainerStyle)
        {
            if (control == item)
            {
                return;
            }
            var parentItemTemplate = parentItemsControl.ItemTemplate;

            if (parentItemTemplate != null)
            {
                control.SetValue(ItemTemplateProperty, parentItemTemplate);
            }
            if (parentItemContainerStyle != null && HasDefaultValue(control, ItemContainerStyleProperty))
            {
                control.SetValue(ItemContainerStyleProperty, parentItemContainerStyle);
            }
            if (control.HeaderIsItem || HasDefaultValue(control, HeaderProperty))
            {
                control.Header       = item;
                control.HeaderIsItem = true;
            }
            if (parentItemTemplate != null)
            {
                control.SetValue(HeaderTemplateProperty, parentItemTemplate);
            }
            if (parentItemContainerStyle != null && control.Style == null)
            {
                control.SetValue(StyleProperty, parentItemContainerStyle);
            }

            var headerTemplate = parentItemTemplate as HierarchicalDataTemplate;

            if (headerTemplate == null)
            {
                return;
            }
            if (headerTemplate.ItemsSource != null && HasDefaultValue(control, ItemsSourceProperty))
            {
                control.SetBinding(ItemsSourceProperty, new Binding
                {
                    Converter          = headerTemplate.ItemsSource.Converter,
                    ConverterLanguage  = headerTemplate.ItemsSource.ConverterLanguage,
                    ConverterParameter = headerTemplate.ItemsSource.ConverterParameter,
                    Mode   = headerTemplate.ItemsSource.Mode,
                    Path   = headerTemplate.ItemsSource.Path,
                    Source = control.Header
                });
            }
            if (headerTemplate.IsItemTemplateSet && control.ItemTemplate == parentItemTemplate)
            {
                control.ClearValue(ItemTemplateProperty);
                if (headerTemplate.ItemTemplate != null)
                {
                    control.ItemTemplate = headerTemplate.ItemTemplate;
                }
            }
            if (!headerTemplate.IsItemContainerStyleSet || control.ItemContainerStyle != parentItemContainerStyle)
            {
                return;
            }
            control.ClearValue(ItemContainerStyleProperty);
            if (headerTemplate.ItemContainerStyle != null)
            {
                control.ItemContainerStyle = headerTemplate.ItemContainerStyle;
            }
        }
        private static void PreparePrepareHeaderedItemsControlContainer(HeaderedItemsControl control, object item, ItemsControl parentItemsControl, Style parentItemContainerStyle)
        {
            if (control == item)
                return;
            var parentItemTemplate = parentItemsControl.ItemTemplate;
            if (parentItemTemplate != null)
            {
                control.SetValue(ItemTemplateProperty, parentItemTemplate);
            }
            if (parentItemContainerStyle != null && HasDefaultValue(control, ItemContainerStyleProperty))
            {
                control.SetValue(ItemContainerStyleProperty, parentItemContainerStyle);
            }
            if (control.HeaderIsItem || HasDefaultValue(control, HeaderProperty))
            {
                control.Header = item;
                control.HeaderIsItem = true;
            }
            if (parentItemTemplate != null)
            {
                control.SetValue(HeaderTemplateProperty, parentItemTemplate);
            }
            if (parentItemContainerStyle != null && control.Style == null)
            {
                control.SetValue(StyleProperty, parentItemContainerStyle);
            }

            var headerTemplate = parentItemTemplate as HierarchicalDataTemplate;
            if (headerTemplate == null)
                return;
            if (headerTemplate.ItemsSource != null && HasDefaultValue(control, ItemsSourceProperty))
            {
                control.SetBinding(ItemsSourceProperty, new Binding
                {
                    Converter = headerTemplate.ItemsSource.Converter,
                    ConverterLanguage = headerTemplate.ItemsSource.ConverterLanguage,
                    ConverterParameter = headerTemplate.ItemsSource.ConverterParameter,
                    Mode = headerTemplate.ItemsSource.Mode,
                    Path = headerTemplate.ItemsSource.Path,
                    Source = control.Header
                });
            }
            if (headerTemplate.IsItemTemplateSet && control.ItemTemplate == parentItemTemplate)
            {
                control.ClearValue(ItemTemplateProperty);
                if (headerTemplate.ItemTemplate != null)
                {
                    control.ItemTemplate = headerTemplate.ItemTemplate;
                }
            }
            if (!headerTemplate.IsItemContainerStyleSet || control.ItemContainerStyle != parentItemContainerStyle)
                return;
            control.ClearValue(ItemContainerStyleProperty);
            if (headerTemplate.ItemContainerStyle != null)
            {
                control.ItemContainerStyle = headerTemplate.ItemContainerStyle;
            }
        }