示例#1
0
        protected FrameworkElement PrepareGroupHeader(GroupHeaderItem headerItem, FrameworkElement lvParent)
        {
            var result = new ListViewGroupHeader()
            {
                Context       = headerItem,
                Content       = headerItem,
                Screen        = _parent.Screen,
                VisualParent  = lvParent,
                LogicalParent = lvParent
            };

            // Set this after the other properties have been initialized to avoid duplicate work
            // No need to set the LogicalParent because styles and content templates don't bind bindings
            result.Style           = MpfCopyManager.DeepCopyCutLVPs(GroupHeaderContainerStyle);
            result.ContentTemplate = MpfCopyManager.DeepCopyCutLVPs(GroupHeaderTemplate);
            return(result);
        }
示例#2
0
        private FrameworkElement GetOrCreateGroupHeader(int itemIndex, HeaderItemWrapper headerWrapper, FrameworkElement lvParent, out bool newCreated)
        {
            if (headerWrapper.HeaderItem != null)
            {
                newCreated = false;
                return(headerWrapper.HeaderItem);
            }
            var headerItem = new GroupHeaderItem()
            {
                FirstItem     = _items[itemIndex],
                GroupingValue = headerWrapper.GroupingValue
            };

            newCreated = true;
            var result = PrepareGroupHeader(headerItem, lvParent);

            headerItem.LogicalParent = result;
            headerWrapper.HeaderItem = result;
            return(result);
        }
示例#3
0
        private HeaderItemWrapper GetGroupHeader(int itemIndex)
        {
            var headerWrapper = _materializedGroupHeaders[itemIndex];

            if (headerWrapper != null)
            {
                return(headerWrapper);
            }

            if (_groupingValueProvider != null)
            {
                headerWrapper = new HeaderItemWrapper(_groupingValueProvider.GetGroupingValue(_items[itemIndex]));
            }
            else
            {
                // to get the grouping value of the item we use a dummy header item and apply the DataContext and group value binding to it
                if (_getValueGroupHeader == null)
                {
                    _getValueGroupHeader = new GroupHeaderItem();
                    var dd      = new SimplePropertyDataDescriptor(_getValueGroupHeader, typeof(GroupHeaderItem).GetProperty("GroupingValue"));
                    var binding = MpfCopyManager.DeepCopyCutLVPs(_groupPropertyBinding);
                    binding.SetTargetDataDescriptor(dd);
                    binding.Activate();
                }

                _getValueGroupHeader.DataContext = new BindingExtension()
                {
                    Source = _items[itemIndex],
                    Path   = "."
                };
                // then we create the actual header item and apply the value to it
                headerWrapper = new HeaderItemWrapper(_getValueGroupHeader.GroupingValue);

                // finally cleanup the datacontext binding
                MPF.TryCleanupAndDispose(_getValueGroupHeader.DataContext);
                _getValueGroupHeader.DataContext = null;
            }
            _materializedGroupHeaders[itemIndex] = headerWrapper;
            return(headerWrapper);
        }