public PracticeCrosswordViewModel(Crossword crossword) { this.crossword = crossword; }
public void Populate(Crossword crossword) { Container.Children.Clear(); wordStrips.Clear(); this.crossword = crossword; boxes = new TextBox[64, 64]; isPrevVertical = false; foreach (var word in crossword.Words) { var strip = new List<TextBox>(); wordStrips[word] = strip; for (int i = 0; i < word.Value.Length; i++) { var x = word.X + (word.Vertical ? 0 : i); var y = word.Y + (word.Vertical ? i : 0); TextBox box = null; if (boxes[x, y] == null) { box = new TextBox { Width = 25, Height = 25, FontSize = 14, VerticalContentAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center, }; box.KeyUp += box_KeyUp; Container.Children.Add(box); Canvas.SetLeft(box, x * 27); Canvas.SetTop(box, 20 + y * 27); Container.Width = Math.Max(Container.Width, Canvas.GetLeft(box) + 50); Container.Height = Math.Max(Container.Height, Canvas.GetTop(box) + 50); boxes[x, y] = box; } else { box = boxes[x, y]; } strip.Add(box); if (i == 0) { var newToolTip = (word.Vertical ? "(Вертикально) " : "(Горизонтально) ") + word.Hint; if ((string)box.ToolTip != string.Empty) { box.BorderThickness = new Thickness(1); if (box.ToolTip == null || (string)box.ToolTip == "") box.ToolTip = newToolTip; else box.ToolTip += "\n" + newToolTip; } else { box.ToolTip = box.ToolTip + " | " + newToolTip; } } } } UpdateState(); }