private void ScrollToProv(Province prov, int previousIndex = -1) { var provIndex = Provinces.Values.Where(p => p && p.Show).OrderBy(p => p.Index).ToList().IndexOf(prov); var tempOffset = (int)(ProvTable.RenderSize.Height / (ProvTable.MinRowHeight + 1) / 2) - 1; var offset = provIndex; if (previousIndex < prov.Index) { offset += tempOffset; } else { offset -= tempOffset; } if (offset >= ProvTable.Items.Count) { offset = ProvTable.Items.Count - 1; } if (previousIndex < 0) { ProvTable.ScrollIntoView(ProvTable.Items[0]); } ProvTable.ScrollIntoView(ProvTable.Items[offset]); }
private void MoveTableToIndex(double tableIndex) { if (ProvTable.Items.Count < 1) { return; } // -2 rows for scroll offset, +1 pixel for horizontal grid line width int index = (int)(tableIndex - 2 + (ProvTable.RenderSize.Height / (ProvTable.MinRowHeight + 1))); if (index >= ProvTable.Items.Count) { index = ProvTable.Items.Count - 1; } ProvTable.ScrollIntoView(ProvTable.Items[index]); }