Multiple data binding objects on a page

валера карманов 396 Reputation points
2024-10-07T18:41:34.15+00:00

There is a code that goes to another page with the data binding specified

await Navigation.PushAsync(new HelpQuestionPage {
	BindingContext = e.CurrentSelection.FirstOrDefault()
});

In the class constructor I get the title to use as the page title

public HelpQuestionPage()
{
	SetBinding(TitleProperty, new Binding { Path = "title" });
}

This is all good, works like clockwork. HOWEVER. There is a function for the class "DataTemplate"

private Layout _GetDataTemplate()
{
	var field = new HelpQuestionRendererField();
	field.SetBindingLabel(Label.TextProperty, new Binding {
		Source = BindingContext, Path = "title"
	});
	var stackLayout = new VerticalStackLayout();
	field.RenderField(stackLayout);
	return stackLayout;
}

It uses the "BindingContext" data binding object, which is bound to the page itself, but I need the data binding that belongs to the "DataTemplate" class. How do I get it?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,596 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.