#c# #xamarin.forms
#c# #xamarin.forms
Вопрос:
Это мой TabbedPage
код:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MojLek.Views.OrdersPage"
xmlns:local="clr-namespace:MyProject.Views"
Title="Orders">
<!--Pages can be added as references or inline-->
<local:NewClaimPage IconImageSource="Add.png" />
</TabbedPage>
NewClaimPage
код:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class NewClaimPage : ContentPage
{
NewClaimPageViewModel viewModel = new NewClaimPageViewModel();
public NewClaimPage()
{
InitializeComponent();
BindingContext = viewModel;
}
protected override void OnAppearing()
{
base.OnAppearing();
viewModel.LoadPatientDoctorsCommand.Execute(null);
}
}
OnAppearing
не запускается, NewClaim
ContentPage не запускается, NewClaimViewModel
не запускается. В чем проблема?
Ответ №1:
Возможно, вы что-то упустили в своей viewmodel. Пожалуйста, проверьте предложения ниже.
Решение1:
Из-за того, что у меня нет подробностей для вашей viewmodel, я делаю простой код для вашей справки. Установите данные в вашей voewmodel:
public class NewClaimPageViewModel
{
public NewClaimPageViewModel()
{
str = "Hello";
}
public string str { get; set; }
}
Привязка в вашем xaml: NewClaimPage
<ContentPage.Content>
<StackLayout>
<Label
HorizontalOptions="CenterAndExpand"
Text="NewClaimPage!"
VerticalOptions="CenterAndExpand" />
<Label Text="{Binding str}" />
</StackLayout>
</ContentPage.Content>
Решение2:
Или вы могли бы BindingContext в вашем NewClaimPage.
<ContentPage.BindingContext>
<vm:NewClaimPageViewModel />
</ContentPage.BindingContext>