public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is HeaderFooter) { return(((HeaderFooter)value).Element); } if (value is SectionCell) { SectionCell sc = (SectionCell)value; ICell cell = null; if (sc.SectionCellRequested != null) { cell = sc.SectionCellRequested(sc.CellIndex, null); } else if (sc.CellRequested != null) { cell = sc.CellRequested(sc.SectionIndex, sc.CellIndex, null); } sc.Cell = cell; CustomItemContainer container = cell as CustomItemContainer; if (container != null) { var custom = container.CustomItem as FrameworkElement; System.Windows.Controls.Grid.SetColumn(custom, sc.SectionIndex % 2); return(custom); } var element = WpfFactory.GetNativeObject <FrameworkElement>(cell, "cell", true); if (element != null) { System.Windows.Controls.Grid.SetColumn(element, sc.SectionIndex % 2); element.Unloaded += (o, e) => { var gridCell = o as IGridCell; var view = parameter as ListView; if (view != null && gridCell != null) { view.SetSubmitValue(gridCell); } }; } return(element); } return(value); }
public void ReloadSections() { if (!firstColumnItems.IsEnabled) { return; } if (ColumnMode == UI.ColumnMode.TwoColumns) { if (secondColumnItems == null) { secondColumnItems = new ListBox() { HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch, ItemContainerStyle = (Style)Resources["ListBoxItemStyle"], ItemTemplateSelector = new CellTemplateSelector(this), BorderThickness = new Thickness(0), Background = firstColumnItems.Background, Padding = new Thickness(8, 0, 10, 0) }; System.Windows.Controls.Grid.SetColumn(secondColumnItems, 1); ScrollViewer.SetHorizontalScrollBarVisibility(secondColumnItems, ScrollBarVisibility.Disabled); ScrollViewer.SetCanContentScroll(secondColumnItems, false); KeyboardNavigation.SetTabNavigation(secondColumnItems, KeyboardNavigationMode.Continue); secondColumnItems.SelectionChanged += (o, e) => { if (e.AddedItems.Count > 0) { firstColumnItems.UnselectAll(); } }; firstColumnItems.SelectionChanged += (o, e) => { if (e.AddedItems.Count > 0 && secondColumnItems != null) { secondColumnItems.UnselectAll(); } }; } if (!container.Children.Contains(secondColumnItems)) { container.ColumnDefinitions.Insert(1, new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); container.Children.Add(secondColumnItems); ScrollViewer.SetVerticalScrollBarVisibility(firstColumnItems, ScrollBarVisibility.Hidden); ScrollViewer.SetCanContentScroll(firstColumnItems, false); var scroller = firstColumnItems.FindChild <ScrollViewer>(null); if (scroller != null) { scroller.ScrollChanged -= SyncScrollBars; scroller.ScrollChanged += SyncScrollBars; } secondColumnItems.ApplyTemplate(); scroller = secondColumnItems.FindChild <ScrollViewer>(null); if (scroller != null) { scroller.ScrollChanged -= SyncScrollBars; scroller.ScrollChanged += SyncScrollBars; } } List <object> firstItems = new List <object>(); for (int i = 0; i < Sections.Count; i += 2) { Section section = Sections[i]; firstItems.Add(new HeaderFooter() { Element = WpfFactory.GetNativeObject <UIElement>(section.Header, "Header", true) }); for (int j = 0; j < section.ItemCount; j++) { var sc = new SectionCell() { CellIndex = j, SectionIndex = i }; if (section.CellRequested != null) { sc.SectionCellRequested = section.CellRequested; } else { sc.CellRequested = CellRequested; } firstItems.Add(sc); } firstItems.Add(new HeaderFooter() { Element = WpfFactory.GetNativeObject <UIElement>(section.Footer, "Footer", true) }); } firstColumnItems.ItemsSource = firstItems; firstColumnItems.Padding = new Thickness(10, 0, 8 + SystemParameters.ScrollWidth, 0); List <object> secondItems = new List <object>(); for (int i = 1; i < Sections.Count; i += 2) { Section section = Sections[i]; secondItems.Add(new HeaderFooter() { Element = WpfFactory.GetNativeObject <UIElement>(section.Header, "Header", true) }); for (int j = 0; j < section.ItemCount; j++) { var sc = new SectionCell() { CellIndex = j, SectionIndex = i }; if (section.CellRequested != null) { sc.SectionCellRequested = section.CellRequested; } else { sc.CellRequested = CellRequested; } secondItems.Add(sc); } secondItems.Add(new HeaderFooter() { Element = WpfFactory.GetNativeObject <UIElement>(section.Footer, "Footer", true) }); } secondColumnItems.ItemsSource = secondItems; } else { if (secondColumnItems != null && container.Children.Contains(secondColumnItems)) { container.Children.Remove(secondColumnItems); container.ColumnDefinitions.RemoveAt(1); ScrollViewer.SetVerticalScrollBarVisibility(firstColumnItems, ScrollBarVisibility.Auto); ScrollViewer.SetCanContentScroll(firstColumnItems, true); var scroller = firstColumnItems.FindChild <ScrollViewer>(null); if (scroller != null) { scroller.ScrollChanged -= SyncScrollBars; } scroller = secondColumnItems.FindChild <ScrollViewer>(null); if (scroller != null) { scroller.ScrollChanged -= SyncScrollBars; } secondColumnItems = null; } var items = new List <object>(); for (int i = 0; i < Sections.Count; i++) { Section section = Sections[i]; items.Add(new HeaderFooter() { Element = WpfFactory.GetNativeObject <UIElement>(section.Header, "Header", true) }); for (int j = 0; j < section.ItemCount; j++) { var sc = new SectionCell() { CellIndex = j, SectionIndex = i }; if (section.CellRequested != null) { sc.SectionCellRequested = section.CellRequested; } else { sc.CellRequested = CellRequested; } items.Add(sc); } items.Add(new HeaderFooter() { Element = WpfFactory.GetNativeObject <UIElement>(section.Footer, "Footer", true) }); } firstColumnItems.ItemsSource = items; firstColumnItems.Padding = new Thickness(0); } }