diff --git a/Xam.Plugin.TabView/Xam.Plugin.TabView.cs b/Xam.Plugin.TabView/Xam.Plugin.TabView.cs index 4900c0f..ce78e0b 100644 --- a/Xam.Plugin.TabView/Xam.Plugin.TabView.cs +++ b/Xam.Plugin.TabView/Xam.Plugin.TabView.cs @@ -56,7 +56,7 @@ public TabViewControl() { //Parameterless constructor required for xaml instantiation. } - + public TabViewControl(IList tabItems, int selectedTabIndex = 0) { Initialize(tabItems, selectedTabIndex); @@ -165,20 +165,20 @@ private void Init() Content = _mainContainerSL; } - protected override void OnBindingContextChanged() - { - base.OnBindingContextChanged(); - if (BindingContext != null) - { - foreach (var tab in ItemSource) - { - if (tab is TabItem view) - { - view.Content.BindingContext = BindingContext; - } - } - } - } + protected override void OnBindingContextChanged() + { + base.OnBindingContextChanged(); + if (BindingContext != null) + { + foreach (var tab in ItemSource) + { + if (tab is TabItem view) + { + view.Content.BindingContext = BindingContext; + } + } + } + } private void _carouselView_PositionSelected(object sender, PositionSelectedEventArgs e) { @@ -199,10 +199,20 @@ private void InitTabs() var tab = ItemSource[i]; tab.IsCurrent = i == _position; + var headerIcon = new Image + { + Margin = new Thickness(0, 20, 0, 0), + BindingContext = tab, + HorizontalOptions = LayoutOptions.CenterAndExpand, + VerticalOptions = LayoutOptions.Center, + WidthRequest = 16, + HeightRequest = 16 + }; + headerIcon.SetBinding(Image.SourceProperty, "HeaderIcon"); var headerLabel = new Label { - Margin = new Thickness(5, 10, 5, 0), + Margin = new Thickness(5, 0, 5, 0), BindingContext = tab, VerticalTextAlignment = TextAlignment.Start, HorizontalTextAlignment = TextAlignment.Center, @@ -240,7 +250,7 @@ private void InitTabs() { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.FillAndExpand, - Children = { headerLabel, selectionBarBoxView } + Children = { headerIcon, headerLabel, selectionBarBoxView } }; var tapRecognizer = new TapGestureRecognizer(); @@ -398,8 +408,9 @@ public static void HeaderTabTextFontAttributesChanged(BindableObject bindable, o public readonly BindableProperty HeaderTabTextFontAttributesProperty = BindableProperty.Create(nameof(HeaderTabTextFontAttributes), typeof(FontAttributes), typeof(TabViewControl), FontAttributes.None, BindingMode.Default, null, HeaderTabTextFontAttributesChanged); #endregion - #region TabItems - public static BindableProperty TabItemsProperty = BindableProperty.Create(nameof(TabItems), typeof(IList), typeof(TabViewControl), null, propertyChanged:OnTabItemsChanged); + + #region TabItems + public static BindableProperty TabItemsProperty = BindableProperty.Create(nameof(TabItems), typeof(IList), typeof(TabViewControl), null, propertyChanged: OnTabItemsChanged); private static void OnTabItemsChanged(BindableObject bindable, object oldValue, object newValue) { if (bindable is TabViewControl tabControl) @@ -415,26 +426,26 @@ public IList TabItems #endregion #region TabSizeOption - public static BindableProperty TabSizeOptionProperty = BindableProperty.Create(nameof(TabSizeOption), typeof(GridLength), typeof(TabViewControl), default(GridLength), propertyChanged: OnTabSizeOptionChanged); - private static void OnTabSizeOptionChanged(BindableObject bindable, object oldValue, object newValue) - { - if (bindable is TabViewControl tabViewControl) - { - if (tabViewControl._headerContainerGrid != null && tabViewControl.ItemSource != null) - { - foreach (var tabContainer in tabViewControl._headerContainerGrid.ColumnDefinitions) - { - tabContainer.Width = (GridLength)newValue; - } - } - } - } - public GridLength TabSizeOption - { - get => (GridLength)GetValue(TabSizeOptionProperty); - set { SetValue(TabSizeOptionProperty, value); } - } - #endregion + public static BindableProperty TabSizeOptionProperty = BindableProperty.Create(nameof(TabSizeOption), typeof(GridLength), typeof(TabViewControl), default(GridLength), propertyChanged: OnTabSizeOptionChanged); + private static void OnTabSizeOptionChanged(BindableObject bindable, object oldValue, object newValue) + { + if (bindable is TabViewControl tabViewControl) + { + if (tabViewControl._headerContainerGrid != null && tabViewControl.ItemSource != null) + { + foreach (var tabContainer in tabViewControl._headerContainerGrid.ColumnDefinitions) + { + tabContainer.Width = (GridLength)newValue; + } + } + } + } + public GridLength TabSizeOption + { + get => (GridLength)GetValue(TabSizeOptionProperty); + set { SetValue(TabSizeOptionProperty, value); } + } + #endregion public void SetPosition(int position) { @@ -528,6 +539,13 @@ public TabItem(string headerText, View content) _content = content; } + public TabItem(string headerText, View content, ImageSource headerIcon) + { + _headerText = headerText; + _content = content; + _headerIcon = headerIcon; + } + private string _headerText; public string HeaderText { @@ -597,6 +615,13 @@ public FontAttributes HeaderTabTextFontAttributes get { return _headerTabTextFontAttributes; } set { SetProperty(ref _headerTabTextFontAttributes, value); } } + + private ImageSource _headerIcon; + public ImageSource HeaderIcon + { + get { return _headerIcon; } + set { SetProperty(ref _headerIcon, value); } + } } public class ObservableBase : INotifyPropertyChanged diff --git a/Xam.Plugin.TabView/Xam.Plugin.TabView.csproj b/Xam.Plugin.TabView/Xam.Plugin.TabView.csproj index 8cb8b0a..727a85d 100644 --- a/Xam.Plugin.TabView/Xam.Plugin.TabView.csproj +++ b/Xam.Plugin.TabView/Xam.Plugin.TabView.csproj @@ -16,6 +16,10 @@ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + SAK + SAK + SAK + SAK true @@ -39,17 +43,17 @@ - - ..\packages\CarouselView.FormsPlugin.5.0.0\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+Xamarin.iOS10\CarouselView.FormsPlugin.Abstractions.dll + + ..\..\..\..\..\..\Software Development\MMA IOS\Source\MMA\packages\CarouselView.FormsPlugin.5.2.0\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid10+Xamarin.iOS10\CarouselView.FormsPlugin.Abstractions.dll - ..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Core.dll + ..\..\..\..\..\..\Software Development\MMA IOS\Source\MMA\packages\Xamarin.Forms.2.5.1.527436\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Core.dll - ..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Platform.dll + ..\..\..\..\..\..\Software Development\MMA IOS\Source\MMA\packages\Xamarin.Forms.2.5.1.527436\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Platform.dll - ..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Xaml.dll + ..\..\..\..\..\..\Software Development\MMA IOS\Source\MMA\packages\Xamarin.Forms.2.5.1.527436\lib\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.Xaml.dll @@ -62,7 +66,9 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + +