Я сталкиваюсь правильно зарегистрированы.
Код: Выделить всё
Type 'TabBar' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter. Missing default constructor for 'StartStudy.TabBar'.
my appshell.xaml :
Код: Выделить всё
Код: Выделить всё
Код: Выделить всё
namespace StartStudy;
public partial class TabBar : ContentPage
{
private readonly HomePage _homePage;
private readonly ProfilePage _profilePage;
// This is the constructor I want to use for Dependency Injection
public TabBar(HomePage homePage, ProfilePage profilePage)
{
_homePage = homePage;
_profilePage = profilePage;
InitializeComponent();
LoadTabContent("Home");
}
private void OnTabTapped(object sender, TappedEventArgs e)
{
var tabName = e.Parameter as string;
if (!string.IsNullOrEmpty(tabName))
{
LoadTabContent(tabName);
UpdateTabVisuals(tabName);
}
}
private void LoadTabContent(string tabName)
{
View contentToLoad = null;
switch (tabName)
{
case "Home":
contentToLoad = _homePage;
break;
case "Profile":
contentToLoad = _profilePage;
break;
default:
contentToLoad = _homePage;
break;
}
if (contentToLoad != null)
{
if (ContentHost.Content != contentToLoad)
UpdateTabVisuals(contentToLoad switch
{
var view when view == _homePage => "Home",
var view when view == _profilePage => "Profile",
_ => "Home"
});
ContentHost.Content = contentToLoad;
}
}
private void UpdateTabVisuals(string activeTabName)
{
var homeContainer = this.FindByName("homeTabContainer");
var profileContainer = this.FindByName("profileTabContainer");
if (homeContainer != null)
{
homeContainer.BackgroundColor = activeTabName == "Home" ? Colors.LightGray : Colors.Transparent;
}
if (profileContainer != null)
{
profileContainer.BackgroundColor = activeTabName == "Profile" ? Colors.LightGray : Colors.Transparent;
}
}
}
Код: Выделить всё
using Microsoft.Extensions.Logging;
using CommunityToolkit.Maui;
using StartStudy.ViewModels; // Assuming AppModelView is here
using StartStudy.Models; // Assuming FileLoader is here
namespace StartStudy
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiCommunityToolkit()
.UseMauiApp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton();
builder.Services.AddTransient();
// All pages are registered as Transient
builder.Services.AddTransient();
builder.Services.AddTransient
();
builder.Services.AddTransient();
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-datatemp