/// <summary> /// /// </summary> /// <param name="pos"></param> public void AddBookmark(double pos) { double bmWidth = 4.0; double MyWidth = this.ActualWidth; if (MyWidth < 147) MyWidth = 147; double posInPixels = MyWidth * (pos / 100); //if (posInPixels < (bmWidth / 2) || posInPixels > this.ActualWidth - (bmWidth / 2)) return; double width = posInPixels; double i = 0; ColumnDefinition newCd; ColumnDefinition bmCd; Bookmark bm; foreach (ColumnDefinition cd in spacers) { width = posInPixels - i; i += cd.Width.Value; if (i - (bmWidth / 2) < posInPixels && posInPixels <= i + (bmWidth * 1.5)) return; if (posInPixels < i) { newCd = new ColumnDefinition(); newCd.Width = new GridLength(width - (bmWidth/2)); bmCd = new ColumnDefinition(); bmCd.Width = new GridLength(bmWidth); int c = grid.ColumnDefinitions.IndexOf(cd); grid.ColumnDefinitions.Insert(c, bmCd); grid.ColumnDefinitions.Insert(c, newCd); cd.Width = new GridLength(cd.Width.Value - (width + (bmWidth * 1.5))); bm = new Bookmark(); bm.Position = pos; bm.RemoveClicked += new EventHandler(Bookmark_RemoveClicked); bm.Clicked += new BookmarkEventHandler(Bookmark_Clicked); foreach (Bookmark b in bookmarks) { if (b.Position > bm.Position) { spacers.Insert(bookmarks.IndexOf(b), newCd); bookmarks.Insert(bookmarks.IndexOf(b), bm); break; } } int j = 1; foreach (Bookmark b in bookmarks) { j += 2; if (b.Position > bm.Position) Grid.SetColumn(b, j); } Grid.SetColumn(bm, c + 1); grid.Children.Add(bm); return; } i += 2.0; } width = posInPixels - i; newCd = new ColumnDefinition(); newCd.Width = new GridLength(width - (bmWidth / 2)); spacers.Add(newCd); bmCd = new ColumnDefinition(); bmCd.Width = new GridLength(bmWidth); grid.ColumnDefinitions.Add(newCd); grid.ColumnDefinitions.Add(bmCd); bm = new Bookmark(); bm.Position = pos; bm.RemoveClicked += new EventHandler(Bookmark_RemoveClicked); bm.Clicked += new BookmarkEventHandler(Bookmark_Clicked); bookmarks.Add(bm); Grid.SetColumn(bm, grid.ColumnDefinitions.Count - 1); grid.Children.Add(bm); }
/// <summary> /// /// </summary> /// <param name="pos"></param> public void AddBookmark(double pos) { double bmWidth = 4.0; double MyWidth = this.ActualWidth; if (MyWidth < 147) { MyWidth = 147; } double posInPixels = MyWidth * (pos / 100); //if (posInPixels < (bmWidth / 2) || posInPixels > this.ActualWidth - (bmWidth / 2)) return; double width = posInPixels; double i = 0; ColumnDefinition newCd; ColumnDefinition bmCd; Bookmark bm; foreach (ColumnDefinition cd in spacers) { width = posInPixels - i; i += cd.Width.Value; if (i - (bmWidth / 2) < posInPixels && posInPixels <= i + (bmWidth * 1.5)) { return; } if (posInPixels < i) { newCd = new ColumnDefinition(); newCd.Width = new GridLength(width - (bmWidth / 2)); bmCd = new ColumnDefinition(); bmCd.Width = new GridLength(bmWidth); int c = grid.ColumnDefinitions.IndexOf(cd); grid.ColumnDefinitions.Insert(c, bmCd); grid.ColumnDefinitions.Insert(c, newCd); cd.Width = new GridLength(cd.Width.Value - (width + (bmWidth * 1.5))); bm = new Bookmark(); bm.Position = pos; bm.RemoveClicked += new EventHandler(Bookmark_RemoveClicked); bm.Clicked += new BookmarkEventHandler(Bookmark_Clicked); foreach (Bookmark b in bookmarks) { if (b.Position > bm.Position) { spacers.Insert(bookmarks.IndexOf(b), newCd); bookmarks.Insert(bookmarks.IndexOf(b), bm); break; } } int j = 1; foreach (Bookmark b in bookmarks) { j += 2; if (b.Position > bm.Position) { Grid.SetColumn(b, j); } } Grid.SetColumn(bm, c + 1); grid.Children.Add(bm); return; } i += 2.0; } width = posInPixels - i; newCd = new ColumnDefinition(); newCd.Width = new GridLength(width - (bmWidth / 2)); spacers.Add(newCd); bmCd = new ColumnDefinition(); bmCd.Width = new GridLength(bmWidth); grid.ColumnDefinitions.Add(newCd); grid.ColumnDefinitions.Add(bmCd); bm = new Bookmark(); bm.Position = pos; bm.RemoveClicked += new EventHandler(Bookmark_RemoveClicked); bm.Clicked += new BookmarkEventHandler(Bookmark_Clicked); bookmarks.Add(bm); Grid.SetColumn(bm, grid.ColumnDefinitions.Count - 1); grid.Children.Add(bm); }