BaconographyWP8.Converters.ReifiedSubredditTemplateCollectionConverter.Convert C# (CSharp) Method

Convert() public method

public Convert ( object value, Type targetType, object parameter, System culture ) : object
value object
targetType System.Type
parameter object
culture System
return object
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection<PivotItem> boundControls = new ObservableCollection<PivotItem>();
            var redditViewModelCollection = value as ObservableCollection<ViewModelBase>;
            redditViewModelCollection.CollectionChanged += (sender, arg) => redditViewModelCollection_CollectionChanged(sender, arg, boundControls);
            foreach (var viewModel in redditViewModelCollection)
            {
                boundControls.Add(MapViewModel(viewModel));
            }


            if (boundControls.Count > 0 && boundControls[0].Content == null)
            {
                boundControls[0].Content = new RedditView { DataContext = boundControls[0].DataContext };
            }

            return boundControls;
        }