public DefaultTabHeaderPanel(ITabControl tabControl, IVisualBootstrapper visualBootstrapper) : base(visualBootstrapper) { _indicatorRect = new RenderRectangle(); _itemsControl = tabControl; _tabsUsed = Size.Empty; _indicatord = Size.Empty; _indicator = new HorizontalRule(visualBootstrapper) { HorizontalAlignment = HorizontalAlignments.Left, Background = visualBootstrapper.ColorPalette.Secondary }; MarginProperty.AddTransition(_indicator, new ThicknessTransition(_indicator, MarginProperty, TimeSpan.FromSeconds(0.3), TimeSpan.Zero, TransitionFunctionType.Ease)); WidthProperty.AddTransition(_indicator, new QuantifiedDoubleTransition(_indicator, WidthProperty, TimeSpan.FromSeconds(0.3), TimeSpan.Zero, TransitionFunctionType.Ease)); _separator = new HorizontalRule(visualBootstrapper); Background = visualBootstrapper.ColorPalette.Background; var stackPanel = new UniformStackPanel(visualBootstrapper) { Orientation = Orientations.Horizontal }; var sourcePropertyAccessor = visualBootstrapper.GetPropertyAccessor( tabControl.GetType(), nameof(tabControl.TabItems)); var spBinding = new OneWayCollectionBinding(tabControl, nameof(tabControl.TabItems), stackPanel, nameof(Children), null, sourcePropertyAccessor); stackPanel.AddBinding(spBinding); _scrollPanel = new ScrollPanel(visualBootstrapper) { Content = stackPanel, ScrollMode = ScrollMode.Horizontal, IsScrollWithMouseDrag = true, VerticalAlignment = VerticalAlignments.Top }; VerticalAlignment = VerticalAlignments.Top; AddChildren(_scrollPanel, _indicator, _separator); tabControl.PropertyChanged += OnTabPropertyChanged; }
static void Main() { // create the source collection ObservableCollection<OrgPerson> personCollection = new ObservableCollection<OrgPerson>(); // populate the source collection personCollection.Add(new OrgPerson("Tom", Position.CEO)); personCollection.Add(new OrgPerson("John", Position.Manager)); // create the target collection List<PrintItem> printCollection = new List<PrintItem>(); // create the binding object OneWayCollectionBinding<OrgPerson, PrintItem> collectionBinding = new OneWayCollectionBinding<OrgPerson, PrintItem> { SourceCollection = personCollection, TargetCollection = printCollection, SourceToTargetItemDelegate = (person) => new PrintItem { StringToPrint = person.Name + " " + person.ThePosition.ToString() } }; // do the binding collectionBinding.Bind(); // prints all the items in the target collection printCollection.PrintItems("Make sure the binding makes the target collection to be in synch with the source collection"); // add an OrgPerson item to the source collection and make sure // the corresponding PrintItem is added to the target collection personCollection.Add(new OrgPerson("Nick", Position.Developer)); printCollection.PrintItems("After adding 'Nick Developer' item to the source collection, make sure it also appears in the target collection"); // remove Tom/CEO item from the source collection and make sure that // the target collection is updated correspondingly OrgPerson ceo = personCollection.Where((person) => person.ThePosition == Position.CEO).FirstOrDefault(); personCollection.Remove(ceo); printCollection.PrintItems("After removing the CEO item from the input collection make sure it also disappeared from the target collection"); }