public Grid FillLyricLineGrid(LyricLine line) { // Create the Grid var grid = new Grid(); grid.Width = 500; //TODO: Auto width grid.HorizontalAlignment = HorizontalAlignment.Left; grid.VerticalAlignment = VerticalAlignment.Top; grid.ShowGridLines = false; grid.Background = new SolidColorBrush(Colors.LightSteelBlue); // Create Columns foreach (var word in line.Lyrics) { var column = new ColumnDefinition{Width = GridLength.Auto}; grid.ColumnDefinitions.Add(column); } // Create Rows var chordRow = new RowDefinition {Height = GridLength.Auto}; var wordRow = new RowDefinition {Height = GridLength.Auto}; grid.RowDefinitions.Add(chordRow); grid.RowDefinitions.Add(wordRow); // Create chord row for (var i = 0; i < line.Lyrics.Count(); i++) { var lyric = line.Lyrics.ToList()[i]; var chordText = new TextBlock {Text = lyric.Chord, FontSize = 12, FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(Colors.Red)}; Grid.SetRow(chordText, 0); Grid.SetColumn(chordText,i); grid.Children.Add(chordText); } // Create lyric row for (var i = 0; i < line.Lyrics.Count(); i++) { var lyric = line.Lyrics.ToList()[i]; var lyricText = new TextBlock { Text = lyric.Text, FontSize = 12 }; Grid.SetRow(lyricText, 1); Grid.SetColumn(lyricText, i); grid.Children.Add(lyricText); } return grid; }
private void btnGridDsp_Click(object sender, RoutedEventArgs e) { var gm = new GridMethods(); var line1 = new LyricLine { HasChords = true, Lyrics = new List<Lyric>{new Lyric("A", "Rock "), new Lyric("", "and "), new Lyric("E", "friggin' "), new Lyric("B", "roll! ")} }; var line2 = new LyricLine { HasChords = true, Lyrics = new List<Lyric> { new Lyric("A", "Set "), new Lyric("", "fire "), new Lyric("E", "to "), new Lyric("", "your "), new Lyric("B", "soul. ") } }; var line3 = new LyricLine { HasChords = true, Lyrics = new List<Lyric> { new Lyric("A", "It's "), new Lyric("", "time "), new Lyric("E", "to "), new Lyric("", "let"), new Lyric("B", "go. ") } }; var line4 = new LyricLine { HasChords = true, Lyrics = new List<Lyric> { new Lyric("A", "Rock, "), new Lyric("", "Rock "), new Lyric("E", "Rock,' "), new Lyric("", "and"), new Lyric("B", "roll! ") } }; var lineList = new List<LyricLine>{line1, line2, line3, line4}; var lineGrids = new List<Grid>(); foreach (var l in lineList) { lineGrids.Add(gm.FillLyricLineGrid(l)); } gm.FillMasterGrid(lineGrids,grid1); }