I have done like this is working fine but when the navigate to pages (TabBarCommand) breaks the my codes without navigation is fine working any solution that you can help me thanks...
xml... custom
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="xxx.Controls.TabBarButton"
x:Name="ButtonTabBar ">
<ContentView.Content>
<Grid RowDefinitions=",,*" HorizontalOptions="Center">
<BoxView x:Name="boxView" HeightRequest="6" WidthRequest="6" CornerRadius="50" HorizontalOptions="Center" Opacity="0" />
<Button x:Name="btnView" Grid.Row="1" FontSize="20" HeightRequest="50" FontFamily="Fontello" BackgroundColor="Transparent" Margin="0,5,0,-5" Clicked="Animate_Click" />
<Label x:Name="lblView" Grid.Row="2" FontSize="12" HorizontalOptions="Center" Opacity="0" />
</Grid>
</ContentView.Content>
</ContentView>
C# .......
public partial class TabBarButton : ContentView
{
public TabBarButton()
{
InitializeComponent();
}
public static readonly BindableProperty DotColorProperty = BindableProperty.Create(
nameof(DotColor),
typeof(Color),
typeof(TabBarButton),
null,
BindingMode.OneWay,
propertyChanged: DotColorChanged);
public Color DotColor
{
get => (Color)GetValue(DotColorProperty);
set => SetValue(DotColorProperty, value);
}
private static void DotColorChanged(BindableObject bindable, object oldValue, object newValue)
{
TabBarButton control = bindable as TabBarButton;
control.boxView.Color = newValue as Color;
}
public static readonly BindableProperty TabBarTextColorProperty = BindableProperty.Create(
nameof(TabBarTextColor),
typeof(Color),
typeof(TabBarButton),
null,
BindingMode.OneWay,
propertyChanged: TabBarTextColorChanged);
public Color TabBarTextColor
{
get => (Color)GetValue(TabBarTextColorProperty);
set => SetValue(TabBarTextColorProperty, value);
}
private static void TabBarTextColorChanged(BindableObject bindable, object oldValue, object newValue)
{
TabBarButton control = bindable as TabBarButton;
control.btnView.TextColor = newValue as Color;
control.lblView.TextColor = newValue as Color;
}
public static readonly BindableProperty TabBarTextProperty = BindableProperty.Create(
nameof(TabBarText),
typeof(string),
typeof(TabBarButton),
null,
BindingMode.OneWay,
propertyChanged: TabBarTextChanged);
public string TabBarText
{
get => (string)GetValue(TabBarTextProperty);
set => SetValue(TabBarTextProperty, value);
}
private static void TabBarTextChanged(BindableObject bindable, object oldValue, object newValue)
{
TabBarButton control = bindable as TabBarButton;
control.lblView.Text = newValue as string;
}
public static readonly BindableProperty TabIconProperty = BindableProperty.Create(
nameof(TabIcon),
typeof(string),
typeof(TabBarButton),
null,
BindingMode.OneWay,
propertyChanged: TabIconChanged);
public string TabIcon
{
get => (string)GetValue(TabIconProperty);
set => SetValue(TabIconProperty, value);
}
private static void TabIconChanged(BindableObject bindable, object oldValue, object newValue)
{
TabBarButton control = bindable as TabBarButton;
control.btnView.Text = newValue as string;
}
public event EventHandler<EventArgs> TabBarButtonClickEvent;
public static readonly BindableProperty TabBarCommandProperty = BindableProperty.Create(
propertyName: nameof(TabBarCommand),
returnType: typeof(ICommand),
declaringType: typeof(TabBarButton),
null,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: TabBarCommandChanged);
public ICommand TabBarCommand
{
get => (ICommand)GetValue(TabBarCommandProperty);
set => SetValue(TabBarCommandProperty, value);
}
private static void TabBarCommandChanged(BindableObject bindable, object oldValue, object newValue)
{
TabBarButton control = bindable as TabBarButton;
control.btnView.Command = (ICommand)newValue;
}
public void AnimatedShow()
{
boxView.FadeTo(1, 300);
lblView.FadeTo(1, 300);
}
public void AnimatedHide()
{
boxView.Opacity=0;
lblView.Opacity=0;
}
private void Animate_Click(object sender, EventArgs e)
{
if (TabBarButtonClickEvent != null)
this.TabBarButtonClickEvent(this, new EventArgs());
}
}
xml.....
<Grid x:Name="gridTabBar" ColumnDefinitions=",,,,*" VerticalOptions="Start" >
<c:TabBarButton x:Name="btnExplore" ClassId="btnExplore" Grid.Column="0" Style="{StaticResource tabButton}" TabBarCommand="{Binding ExploreCommand, Source={x:Reference BaseTabBar}}" TabIcon="{StaticResource icon-explore}" TabBarText="Explore" />
<c:TabBarButton x:Name="btnCategory" ClassId="btnCategory" Grid.Column="1" Style="{StaticResource tabButton}" TabBarCommand="{Binding CategoriesCommand, Source={x:Reference BaseTabBar}}" TabIcon="{StaticResource icon-category}" TabBarText="Categories" />
<c:TabBarButton x:Name="btnFavorite" ClassId="btnFavorite" Grid.Column="3" Style="{StaticResource tabButton}" TabBarCommand="{Binding FavoritesCommand, Source={x:Reference BaseTabBar}}" TabIcon="{StaticResource icon-star}" TabBarText="My Favorites" />
<c:TabBarButton x:Name="btnEvent" ClassId="btnEvent" Grid.Column="4" Style="{StaticResource tabButton}" TabBarCommand="{Binding EventsCommand, Source={x:Reference BaseTabBar}}" TabIcon="{StaticResource icon-events}" TabBarText="My Events" />
</Grid>
c#.....
public CustomTabBar()
{
InitializeComponent();
btnExplore.TabBarButtonClickEvent += Btn_TabBarButtonClickEvent;
btnCategory.TabBarButtonClickEvent += Btn_TabBarButtonClickEvent;
btnFavorite.TabBarButtonClickEvent += Btn_TabBarButtonClickEvent;
btnEvent.TabBarButtonClickEvent += Btn_TabBarButtonClickEvent;
}
private void Btn_TabBarButtonClickEvent(object sender, EventArgs e)
{
var name = ((TabBarButton)sender).ClassId;
foreach (var item in gridTabBar.Children)
{
if (item.GetType() == typeof(TabBarButton))
{
var btn = (TabBarButton)item;
if (btn.ClassId == name)
{
btn.AnimatedShow();
}
else
{
btn.AnimatedHide();
}
}
}
}