Hi all
I have - hope so - a trivial problem for the crack's...
I want to access an object on a page (e.g. label, stacklayout, etc.) from a function (in page-class) e.g. to make it visible / invisible or to update text to a label.
If I access an object from an event-handler in the page-class (e.g. item.tapped) it works.
If I want to access the object from an own function, the object is “not known in this context”.
I have tried this. page. pagename. - nothing works...
What do I have to do, to access an object on the page from a function…?
Thanks for any suggestion...
Concrete example (note: do't care about the messagingcenter and the stacklayout - I also have the problem with a simple label):
Definition of object:
var DatenLadenIndicator = new ActivityIndicator
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
Color = Color.Black,
IsRunning = true,
IsVisible = true,
};
var DatenLadenLabel = new Label { Text = "Daten werden geladen...", Font = Font.SystemFontOfSize(20, FontAttributes.Bold) };
var DatenLadenElement = new StackLayout { Children = { DatenLadenLabel, DatenLadenIndicator } };
DatenLadenElement.IsVisible = false;
The DatenLadenElement then is added to the page-content:
Content = new StackLayout // Inhalt Page aufbereiten
{
Padding = 10,
Children =
{
DatenLadenElement,
LSortierung,
LVSortierung,
lStatusAbfrage,
lvErgebnisAnzeige,
}
Function to show/hide the DatenLadenElement:
public void DatenLadenAnzeigen()
{
DatenLadenElement.IsVisible = true;
MessagingCenter.Subscribe<GV.UpdateStatusMessageData>(this, GV.UpdateStatusMessageData.MessageIDAbfrageBeendet, async (msg) =>
{
DatenLadenElement.IsVisible = false;
MessagingCenter.Unsubscribe<GV.UpdateStatusMessageData>(this, GV.UpdateStatusMessageData.MessageIDAbfrageBeendet);
});
return;
}