这是我的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没有被解雇。有什么问题吗?
发布于 2020-10-09 07:37:22
也许你错过了什么东西在你的视图模型。请核对以下建议。
Solution1:
由于我没有您的视图模型的详细信息,所以我编写了一个简单的代码供您参考。在您的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>Solution2:
或者你可以在你的BindingContext中使用NewClaimPage。
<ContentPage.BindingContext>
<vm:NewClaimPageViewModel />
</ContentPage.BindingContext> https://stackoverflow.com/questions/64261286
复制相似问题