Xamarin导航页面的绑定标题



我遇到了一个小问题。我得到了一个搜索页面,如果你点击搜索中的一个项目,你会使用导航页面得到另一个页面。我希望将此页面的标题设置为单击的项目。这是我得到的:

private async void PatListe_ItemTapped(object sender, ItemTappedEventArgs e)
{
if (e.Item is Patient pat)
{
PatNN = pat.NName.ToString();
PatVN = pat.VName.ToString();
PatInt = pat.Fallnummer;
}
PatVN_NN = PatNN + " " + PatVN;
await Navigation.PushAsync(new PatientView());
}

所以这给了我想要的标题的"名字"。通过调试和停止点,我注意到这是可行的。现在我猜有两个错误,一个在另一个网站的.cs和.xaml文件中。这是我的.cs文件中的一个:

private string PatNameTitle = SuchErgebnisse.PatVN_NN;  

在调试时,我意识到这没有得到任何值,它为null。但是:我在PatInt上也得到了同样的结果,这正在起作用。。。但即使这是有效的,在我的xaml文件中还有另一个错误:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="INESVitaAppTest.Views.PatientenView" BackgroundColor="#235d2a" Title="{Binding PatNameTitle}">

即使在我使用字符串(如"PatNameTitle="foo";"非常感谢!

该死,我明白了。PatNameTitle没有初始化。。。。这是我添加的内容:

Title = PatNameTitle;

在打开此页面时调用的方法中。。ant然后我删除了Title="{Binding..}"-东西,现在它正在工作:(对不起

最新更新