【发布时间】:2021-12-13 11:56:22
【问题描述】:
有人知道如何从模型中绑定页面标题吗?我想将 Name 属性设置为 Title Page 下面是我的代码
Xaml
<ContentPage BackgroundColor="White"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="app.MainMenuPage"
NavigationPage.HasBackButton="False">
<NavigationPage.TitleView>
<StackLayout>
<Label Text="{Binding Name}"/>
</StackLayout>
</NavigationPage.TitleView>
我的模特
public class EmployeeDetails
{
public string PersonnelNumber { get; set; }
public string PrimaryContactEmail { get; set; }
public string Name { get; set; }
}
【问题讨论】:
-
应该可以。 BindingContext 分配了吗?
-
当我悬停绑定名称时,我收到警告/错误 No DataContext found for Binding Name
-
你没有回答问题
-
可能这就是我不知道如何分配绑定上下文的原因我对 xamarin 不熟悉如何做到这一点?
-
this.BindingContext = new MyViewModel();
标签: c# xamarin.forms mobile