private static void OnListCharactersPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { ListCharactersWithLink control = source as ListCharactersWithLink; control.rankingListStackPanel.Children.Clear(); Character[] listCharacters = (Character[])e.NewValue; if (listCharacters != null) { listCharacters.ToList().ForEach(character => AddLinkedElement(control, character)); } }
private static void AddLinkedElement(ListCharactersWithLink control, Character character) { TextBlock textBlockCharacterName = new TextBlock(); textBlockCharacterName.Margin = new Thickness(10, 5, 0, 0); textBlockCharacterName.FontSize = 16; textBlockCharacterName.Text = character.Name; textBlockCharacterName.Foreground = Brushes.Navy; textBlockCharacterName.Cursor = Cursors.Hand; if (control.ShowPosition) { StackPanel stackPanelElement = new StackPanel(); stackPanelElement.Orientation = Orientation.Horizontal; stackPanelElement.Cursor = Cursors.Hand; stackPanelElement.Tag = character.Id; stackPanelElement.MouseLeftButtonDown += FrameworkElement_MouseLeftButtonDown; TextBlock textBlockRankingNumber = new TextBlock(); textBlockRankingNumber.Margin = new Thickness(20, 5, 0, 0); textBlockRankingNumber.FontSize = 16; textBlockRankingNumber.Text = (control.rankingListStackPanel.Children.Count + 1).ToString(); textBlockRankingNumber.Foreground = Brushes.Navy; textBlockRankingNumber.Cursor = Cursors.Hand; stackPanelElement.Children.Add(textBlockRankingNumber); stackPanelElement.Children.Add(textBlockCharacterName); control.rankingListStackPanel.Children.Add(stackPanelElement); } else { textBlockCharacterName.Tag = character.Id; textBlockCharacterName.MouseLeftButtonDown += FrameworkElement_MouseLeftButtonDown; control.rankingListStackPanel.Children.Add(textBlockCharacterName); } }