Я создаю кросс-платформенное приложение .NET Maui, и я создал интрапейдную адаптацию с помощью CarouselView , связанной с ViewModel . Страница отлично работает на Android , но на Windows , поведение сломано:
Страница случайно открывается на не первой странице каруселей , даже если я установил CurrentIndex = 0 in на первой () . /> Левая/правая кнопки сгруппировать карусель вместо правильного перемещения.
< /code>
intropage.xaml.cs
namespace restaurant;
public partial class IntroPage : ContentPage
{
public IntroPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
if (BindingContext is ViewModels.IntroViewModel vm)
{
vm.CurrentIndex = 0;
}
}
}
< /code>
introviewmodel.cs
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls;
namespace restaurant.ViewModels
{
internal class IntroViewModel : INotifyPropertyChanged
{
public ObservableCollection Pages { get; }
private int _currentIndex;
public int CurrentIndex
{
get => _currentIndex;
set
{
if (_currentIndex != value)
{
_currentIndex = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IsFirstPage));
OnPropertyChanged(nameof(IsNotFirstPage));
OnPropertyChanged(nameof(IsLastPage));
OnPropertyChanged(nameof(IsNotLastPage));
OnPropertyChanged(nameof(CurrentItem));
}
}
}
public IntroPageModel CurrentItem => (CurrentIndex >= 0 && CurrentIndex < Pages.Count)
? Pages[CurrentIndex]
: null;
public bool IsFirstPage => CurrentIndex == 0;
public bool IsNotFirstPage => !IsFirstPage;
public bool IsLastPage => CurrentIndex == Pages.Count - 1;
public bool IsNotLastPage => !IsLastPage;
public ICommand NextCommand { get; }
public ICommand PreviousCommand { get; }
public ICommand LoginCommand { get; }
public ICommand SignUpCommand { get; }
public IntroViewModel()
{
Pages = new ObservableCollection
{
new IntroPageModel { Title = "Welcome!", Description = "Manage your restaurant with SIMR Admin.", Image = "intro1.png" },
new IntroPageModel { Title = "Track Orders", Description = "Monitor food orders and ingredients.", Image = "intro2.png" },
new IntroPageModel { Title = "Analyze Statistics", Description = "Gain insights on your restaurant's performance.", Image = "intro3.png" },
new IntroPageModel { Title = "Get Started", Description = "Login or sign up to begin using SIMR Admin.", Image = "intro4.png" }
};
CurrentIndex = 0;
NextCommand = new Command(() =>
{
if (IsNotLastPage)
CurrentIndex++;
});
PreviousCommand = new Command(() =>
{
if (IsNotFirstPage)
CurrentIndex--;
});
LoginCommand = new Command(async () =>
await Application.Current.MainPage.Navigation.PushAsync(new LoginPage()));
SignUpCommand = new Command(async () =>
await Application.Current.MainPage.Navigation.PushAsync(new RegisterPage()));
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
internal class IntroPageModel
{
public string Title { get; set; }
public string Description { get; set; }
public string Image { get; set; }
}
}
Что я попробовал:
Настройка CurrentIndex = 0 явно в OnapeAring () .
removing indicatorView
removing indicatorView
removing indicatorview /> Отключение Isscrollanimated и iSbounceenabled .
Проверка привязки, которые правильно запускаются с помощью журналов отладки. 0 .
Мой вопрос:
Почему Carouselview ведут себя по -разному в Windows vs Android в .net Maui, и как я могу исправить глики, и всегда будет начинать на первой странице с правильной страницей? ценится. Я использую: < /p>
< /li>
Windows 11 < /p>
< /li>
Visual Studio 2022 (последнее) < /p>
< /li> < /> >
Я создаю кросс-платформенное приложение .NET Maui, и я создал интрапейдную адаптацию с помощью CarouselView , связанной с ViewModel . Страница отлично работает на [b] Android [/b], но на Windows , поведение сломано: [list] [*] Страница [b] случайно открывается на не первой странице каруселей , даже если я установил CurrentIndex = 0 in на первой () . /> Левая/правая кнопки сгруппировать карусель [/b] вместо правильного перемещения.[code]Login[/code], регистрация ) также не показывайте/скрыть правильно.[code]
< /code> intropage.xaml.cs namespace restaurant;
public partial class IntroPage : ContentPage { public IntroPage() { InitializeComponent(); }
protected override void OnAppearing() { base.OnAppearing(); if (BindingContext is ViewModels.IntroViewModel vm) { vm.CurrentIndex = 0; } } } < /code> introviewmodel.cs using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Input; using Microsoft.Maui.Controls;
namespace restaurant.ViewModels { internal class IntroViewModel : INotifyPropertyChanged { public ObservableCollection Pages { get; }
private int _currentIndex; public int CurrentIndex { get => _currentIndex; set { if (_currentIndex != value) { _currentIndex = value; OnPropertyChanged(); OnPropertyChanged(nameof(IsFirstPage)); OnPropertyChanged(nameof(IsNotFirstPage)); OnPropertyChanged(nameof(IsLastPage)); OnPropertyChanged(nameof(IsNotLastPage)); OnPropertyChanged(nameof(CurrentItem)); } } }
public bool IsFirstPage => CurrentIndex == 0; public bool IsNotFirstPage => !IsFirstPage; public bool IsLastPage => CurrentIndex == Pages.Count - 1; public bool IsNotLastPage => !IsLastPage;
public ICommand NextCommand { get; } public ICommand PreviousCommand { get; } public ICommand LoginCommand { get; } public ICommand SignUpCommand { get; }
public IntroViewModel() { Pages = new ObservableCollection { new IntroPageModel { Title = "Welcome!", Description = "Manage your restaurant with SIMR Admin.", Image = "intro1.png" }, new IntroPageModel { Title = "Track Orders", Description = "Monitor food orders and ingredients.", Image = "intro2.png" }, new IntroPageModel { Title = "Analyze Statistics", Description = "Gain insights on your restaurant's performance.", Image = "intro3.png" }, new IntroPageModel { Title = "Get Started", Description = "Login or sign up to begin using SIMR Admin.", Image = "intro4.png" } };
CurrentIndex = 0;
NextCommand = new Command(() => { if (IsNotLastPage) CurrentIndex++; });
PreviousCommand = new Command(() => { if (IsNotFirstPage) CurrentIndex--; });
LoginCommand = new Command(async () => await Application.Current.MainPage.Navigation.PushAsync(new LoginPage()));
SignUpCommand = new Command(async () => await Application.Current.MainPage.Navigation.PushAsync(new RegisterPage())); }
public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }
internal class IntroPageModel { public string Title { get; set; } public string Description { get; set; } public string Image { get; set; } } } [/code] Что я попробовал:
[*] Проверка привязки, которые правильно запускаются с помощью журналов отладки. 0 .
[/list] Мой вопрос: Почему Carouselview ведут себя по -разному в Windows vs Android в .net Maui, и как я могу исправить глики, и всегда будет начинать на первой странице с правильной страницей? ценится. Я использую: < /p>
< /li> Windows 11 < /p> < /li> Visual Studio 2022 (последнее) < /p> < /li> < /> >