private static void OnItemsSet(DependencyObject d, DependencyPropertyChangedEventArgs e) { // If the Items property is set, create new ScoreBoardItem controls for each item, bind the appropriate values, and subscribe to any events. var scoreBoard = d as ScoreBoard; if (e.NewValue != null) { var collection = (ObservableCollection <CountryResultsViewModel>)e.NewValue; foreach (var countryResultsViewModel in collection) { var scoreBoardItem = new ScoreBoardItem() { DataContext = countryResultsViewModel, Opacity = 0 }; var binding = new Binding("TotalPoints"); binding.Source = countryResultsViewModel; scoreBoardItem.SetBinding(ScoreBoardItem.TotalPointsProperty, binding); scoreBoardItem.CurrentPointsUpdated += scoreBoard.ScoreBoardItem_CurrentPointsUpdated; scoreBoard.AddScoreBoardItem(scoreBoardItem); } } }
private static void BindItemWidthToScoreBoardWidth(ScoreBoardItem scoreBoardItem) { Binding widthBinding = new Binding("ActualWidth"); widthBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ScoreBoard), 1); scoreBoardItem.SetBinding(ScoreBoardItem.WidthProperty, widthBinding); }