首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TabbedPage未加载子页面BindingContext

TabbedPage未加载子页面BindingContext
EN

Stack Overflow用户
提问于 2020-10-08 11:09:29
回答 1查看 96关注 0票数 0

这是我的TabbedPage代码:

代码语言:javascript
复制
<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代码:

代码语言:javascript
复制
[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没有被解雇。有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-09 07:37:22

也许你错过了什么东西在你的视图模型。请核对以下建议。

Solution1:

由于我没有您的视图模型的详细信息,所以我编写了一个简单的代码供您参考。在您的voewmodel中设置数据:

代码语言:javascript
复制
  public class NewClaimPageViewModel
{
    public NewClaimPageViewModel()
    {
        str = "Hello";
    }
    public string str { get; set; }
}

xaml: NewClaimPage中的绑定

代码语言:javascript
复制
<ContentPage.Content>
    <StackLayout>
        <Label
            HorizontalOptions="CenterAndExpand"
            Text="NewClaimPage!"
            VerticalOptions="CenterAndExpand" />
        <Label Text="{Binding str}" />
    </StackLayout>
</ContentPage.Content>

Solution2:

或者你可以在你的BindingContext中使用NewClaimPage。

代码语言:javascript
复制
 <ContentPage.BindingContext>
    <vm:NewClaimPageViewModel />
</ContentPage.BindingContext> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64261286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档