/// <summary> /// Updates the controls selection based on the specified area. /// </summary> /// <param name="area"> /// The selection area, relative to the control passed in the contructor. /// </param> public void UpdateSelection(Rect area) { // Check eack item to see if it intersects with the area. for (int i = 0; i < this.itemsControl.Items.Count; i++) { AyTableViewCellsPresenter item = this.itemsControl.ItemContainerGenerator.ContainerFromIndex(i) as AyTableViewCellsPresenter; if (item != null) { // Get the bounds in the parent's co-ordinates. Point topLeft = item.TranslatePoint(new Point(0, 0), this.itemsControl); Rect itemBounds = new Rect(topLeft.X, topLeft.Y, item.ActualWidth, item.ActualHeight); // Only change the selection if it intersects with the area // (or intersected i.e. we changed the value last time). if (itemBounds.IntersectsWith(area)) { item.isMouseLeftDown = 2; item.IsSelected = true; item.isMouseLeftDown = 1; if (!item.ParentTableView.SelectedItems.Contains(item.Item)) { item.ParentTableView.SelectedItems.Add(item.Item); } } else if (itemBounds.IntersectsWith(this.previousArea)) { item.isMouseLeftDown = 2; item.IsSelected = false; item.isMouseLeftDown = 1; if (item.ParentTableView.SelectedItems.Contains(item.Item)) { item.ParentTableView.SelectedItems.Remove(item.Item); } } } } this.previousArea = area; }
public void PrepareCell(AyTableViewCellsPresenter parent, int idx) { ParentCellsPresenter = parent; ParentTableView = parent.ParentTableView; var column = ParentTableView.Columns[idx]; //IsSelected = ParentCellsPresenter.IsSelected() && (ParentTableView.FocusedColumnIndex == column.ColumnIndex); if (_column != column) { _column = column; this.Width = column.Width; BindingOperations.ClearBinding(this, WidthProperty); BindingOperations.SetBinding(this, WidthProperty, column.WidthBinding); Focusable = ParentTableView.CellNavigation; BindingOperations.ClearBinding(this, ColumnFocusBrushProperty); BindingOperations.SetBinding(this, ColumnFocusBrushProperty, new Binding { Source = _column, Mode = BindingMode.TwoWay, Path = new PropertyPath("ColumnFocusBrush") }); } column.GenerateCellContent(this); }
protected override DependencyObject GetContainerForItemOverride() { var container = new AyTableViewCellsPresenter(); return(container); }