} // ListViewLayoutWindow // ---------------------------------------------------------------------- private void SetupCustomers(ListView listView) { new ListViewLayoutManager(listView); // apply layout manager GridView gridView = new GridView(); gridView.Columns.Add(FixedColumn.ApplyWidth(new CustomerStateGridViewColumn("State"), 25)); gridView.Columns.Add(ProportionalColumn.ApplyWidth(new CustomerGridViewColumn(CustomerColumn.FirstName, "Fist Name (Proportional=1)"), 1)); gridView.Columns.Add(ProportionalColumn.ApplyWidth(new CustomerGridViewColumn(CustomerColumn.LastName, "Last Name (Proportional=1)"), 1)); gridView.Columns.Add(ProportionalColumn.ApplyWidth(new CustomerGridViewColumn(CustomerColumn.Address, "Address (Proportional=2)"), 2)); listView.View = gridView; listView.ItemsSource = Customers; } // SetupCustomers
/// <summary> /// Registers on the wanted events on the dependency object. /// </summary> /// <param name="pObject">The object on witch to register the delegates.</param> private void RegisterEvents(DependencyObject pObject) { for (int lIter = 0; lIter < VisualTreeHelper.GetChildrenCount(pObject); lIter++) { Visual lChildVisual = VisualTreeHelper.GetChild(pObject, lIter) as Visual; if (lChildVisual is Thumb) { GridViewColumn lColumn = this.FindParentColumn(lChildVisual); if (lColumn != null) { Thumb lThumb = lChildVisual as Thumb; if (FixedColumn.IsFixedColumn(lColumn) || this.IsFillColumn(lColumn)) { // Do not allow resize on the fixed column. lThumb.IsHitTestVisible = false; } else { // Registering. lThumb.PreviewMouseMove += new MouseEventHandler(this.OnThumbPreviewMouseMove); lThumb.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.OnThumbPreviewMouseLeftButtonDown); DependencyPropertyDescriptor.FromProperty(GridViewColumn.WidthProperty, typeof(GridViewColumn)).AddValueChanged(lColumn, this.OnGridColumnWidthChanged); } } } else if (lChildVisual is GridViewColumnHeader) { GridViewColumnHeader lColumnHeader = lChildVisual as GridViewColumnHeader; lColumnHeader.SizeChanged += new SizeChangedEventHandler(this.OnGridColumnHeaderSizeChanged); } else if (this.mScrollViewer == null && lChildVisual is ScrollViewer) { this.mScrollViewer = lChildVisual as ScrollViewer; this.mScrollViewer.ScrollChanged += new ScrollChangedEventHandler(this.OnScrollViewerScrollChanged); // Saving the current scrollbar parameters. this.mBackupHorizontalScrollBarVisibility = this.mScrollViewer.HorizontalScrollBarVisibility; this.mBackupVerticalScrollBarVisibility = this.mScrollViewer.VerticalScrollBarVisibility; // Assume we do the regulation of the horizontal scrollbar. this.mScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; this.mScrollViewer.VerticalScrollBarVisibility = this.mVerticalScrollBarVisibility; } this.RegisterEvents(lChildVisual); } }
/// <summary> /// Delegate called when a column width change. /// </summary> /// <param name="pSender">The event sender.</param> /// <param name="pEventArgs">The event arguments.</param> private void OnGridColumnWidthChanged(object pSender, EventArgs pEventArgs) { if (this.mLoaded == false) { return; } GridViewColumn lColumn = pSender as GridViewColumn; if (lColumn == null) { return; } // Suppress column resizing for fixed columns. if (FixedColumn.IsFixedColumn(lColumn)) { return; } // Ensure range column within the bounds. if (RangeColumn.IsRangeColumn(lColumn)) { // Special case: auto column width - maybe conflicts with min/max range. if (lColumn != null && lColumn.Width.Equals(double.NaN)) { // Resize is handled by the change header size event. this.mAutoSizedColumn = lColumn; return; } // ensure column bounds if (Math.Abs(this.SetRangeColumnToBounds(lColumn) - 0) > ZERO_WIDTH_RANGE) { return; } } // Force resize. this.DoResizeColumns(this.mListView.View.Columns.IndexOf(lColumn)); }
/// <summary> /// Unregisters from the wanted events of the dependency object. /// </summary> /// <param name="pObject">The object on witch to unregister the delegates.</param> private void UnregisterEvents(DependencyObject pObject) { for (int lIter = 0; lIter < VisualTreeHelper.GetChildrenCount(pObject); lIter++) { Visual lChildVisual = VisualTreeHelper.GetChild(pObject, lIter) as Visual; if (lChildVisual is Thumb) { GridViewColumn lColumn = this.FindParentColumn(lChildVisual); if (lColumn != null) { Thumb lThumb = lChildVisual as Thumb; if (FixedColumn.IsFixedColumn(lColumn) || this.IsFillColumn(lColumn)) { lThumb.IsHitTestVisible = true; } else { lThumb.PreviewMouseMove -= new MouseEventHandler(this.OnThumbPreviewMouseMove); lThumb.PreviewMouseLeftButtonDown -= new MouseButtonEventHandler(this.OnThumbPreviewMouseLeftButtonDown); DependencyPropertyDescriptor.FromProperty(GridViewColumn.WidthProperty, typeof(GridViewColumn)).RemoveValueChanged(lColumn, this.OnGridColumnWidthChanged); } } } else if (lChildVisual is GridViewColumnHeader) { GridViewColumnHeader lColumnHeader = lChildVisual as GridViewColumnHeader; lColumnHeader.SizeChanged -= new SizeChangedEventHandler(this.OnGridColumnHeaderSizeChanged); } else if (this.mScrollViewer == null && lChildVisual is ScrollViewer) { this.mScrollViewer = lChildVisual as ScrollViewer; this.mScrollViewer.ScrollChanged -= new ScrollChangedEventHandler(this.OnScrollViewerScrollChanged); // Back applying the scrollbar states. this.mScrollViewer.HorizontalScrollBarVisibility = this.mBackupHorizontalScrollBarVisibility; this.mScrollViewer.VerticalScrollBarVisibility = this.mBackupVerticalScrollBarVisibility; } this.UnregisterEvents(lChildVisual); } }
/// <summary> /// Delegate called when a mouse left button is down on a thumb. /// </summary> /// <param name="pSender">The event sender.</param> /// <param name="pEventArgs">The event arguments.</param> private void OnThumbPreviewMouseLeftButtonDown(object pSender, MouseButtonEventArgs pEventArgs) { Thumb lThumb = pSender as Thumb; if (lThumb == null) { return; } GridViewColumn lColumn = this.FindParentColumn(lThumb); if (lColumn == null) { return; } // Suppress column resizing for fixed and range fill columns. if (FixedColumn.IsFixedColumn(lColumn) || this.IsFillColumn(lColumn)) { pEventArgs.Handled = true; } }
private ColumnSource[] CreateColumnsFromColumnMetadata(IList <ColumnMetadata> columns, IColumnStorage columnStorage, PartitionConfig configOverride, int partitionID) { var resultColumns = new ColumnSource[columns.Count]; var recordHint = _settings.RecordHint; if (configOverride != null) { columns = ParseColumns(columns.Select(c => c.SerializerMetadata), configOverride.Columns); recordHint = configOverride.RecordHint; } int fileID = 0; for (int columnID = 0; columnID < columns.Count; columnID++) { var cType = columns[columnID]; // Build. IColumn column; if (cType.ColumnType == EFieldType.String) { // String. var data = columnStorage.GetFile(cType, fileID++, EDataType.Data, recordHint); var index = columnStorage.GetFile(cType, fileID++, EDataType.Index, recordHint); column = new StringColumn(data, index, cType.MaxSize, GetPropertyName(cType.FileName)); } else if (cType.ColumnType == EFieldType.BitSet) { var data = columnStorage.GetFile(cType, fileID++, EDataType.Data, recordHint); column = new BitsetColumn(data, cType.MaxSize); } else if (cType.ColumnType == EFieldType.Symbol) { var colData = columnStorage.GetFile(cType, fileID++, EDataType.Data, recordHint); var symData = columnStorage.GetFile(cType, fileID++, EDataType.Symd, recordHint); var symi = columnStorage.GetFile(cType, fileID++, EDataType.Symi, recordHint); var symk = columnStorage.GetFile(cType, fileID++, EDataType.Symrk, recordHint); var symr = columnStorage.GetFile(cType, fileID++, EDataType.Symrr, recordHint); int maxLen = cType.MaxSize; int distinctHintCount = cType.HintDistinctCount; if (cType.Indexed) { var colDataK = columnStorage.GetFile(cType, fileID++, EDataType.Datak, recordHint); var colDataR = columnStorage.GetFile(cType, fileID++, EDataType.Datar, recordHint); column = new SymbolMapColumn( columnID, partitionID, data: colData, datak: colDataK, datar: colDataR, symd: symData, symi: symi, symk: symk, symr: symr, propertyName: GetPropertyName(cType.FileName), capacity: distinctHintCount, recordCountHint: _settings.RecordHint, maxLen: maxLen); } else { column = new SymbolMapColumn( columnID, partitionID, data: colData, symd: symData, symi: symi, symk: symk, symr: symr, propertyName: GetPropertyName(cType.FileName), capacity: distinctHintCount, maxLen: maxLen); } } else if (cType.ColumnType == EFieldType.Binary) { // Byte array. var data = columnStorage.GetFile(cType, fileID++, EDataType.Data, recordHint); var index = columnStorage.GetFile(cType, fileID++, EDataType.Index, recordHint); column = new BinaryColumn(data, index, cType.MaxSize, GetPropertyName(cType.FileName)); } else { // Fixed size. var data = columnStorage.GetFile(cType, fileID++, EDataType.Data, recordHint); column = new FixedColumn(data, cType.ColumnType, GetPropertyName(cType.FileName)); } resultColumns[columnID] = new ColumnSource(cType, column, fileID); } return(resultColumns); }