maui
maui copied to clipboard
[MISSING DEPRECATION] Non-firing function overrides like OnMeasure and OnAppearing should be marked as deprecated
Description
In .NET MAUI 9.0 Preview 2.0, there are several overrideable function such as OnMeasure and OnAppearing (for content pages) that do not fire anymore. If they are intended to be deprecated, they should be marked accordingly with a remark that they do not fire in MAUI, as opposed to Xamarin.
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
9.0.0-preview.1.9973
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
Yes, using still firing events.
Relevant log output
No response
Could you please provide a sample of what you are trying to do and wat isn't work?
First, I was using in Xamarin override OnMeasure of SKCanvasView to make it autosizing. OnMeasure does not fire anymore in Maui for SKCanvasView, and there is a new MeasureOverride function, that fires instead (yet is bugged, but that is a separate topic). It is not obvious coming from Xamarin that OnMeasure does not fire, so it would be great that there would be a warning saying so (being deprecated in Maui).
Second, in Xamarin, I was using overring OnAppearing function for a content page as follows:
protected override void OnAppearing()
{
base.OnAppearing();
if(_gamePage.PlayingReplay)
{
if(!string.IsNullOrWhiteSpace(_replayEnteredName))
{
Device.StartTimer(TimeSpan.FromMilliseconds(GHConstants.ReplayAskNameDelay1), () =>
{
ReplayDoEnterName();
return false;
});
}
}
else
{
eName.Focus();
}
}
However, it turns out that OnAppearing does not fire in Maui, which would be great to get a warning about. Instead, you have to use ContentPage_Appearing event or ContentPage_Loaded event. So in Maui, the code is now as follows:
public NamePage()
{
InitializeComponent();
Loaded += ContentPage_Loaded;
}
private void ContentPage_Loaded(object sender, EventArgs e)
{
if (_gamePage.PlayingReplay)
{
if (!string.IsNullOrWhiteSpace(_replayEnteredName))
{
var timer = Microsoft.Maui.Controls.Application.Current.Dispatcher.CreateTimer();
timer.Interval = TimeSpan.FromSeconds(UIUtils.GetWindowHideSecs());
timer.IsRepeating = false;
timer.Tick += (s, e) => { ReplayDoEnterName(); };
timer.Start();
}
}
else
{
eName.Focus();
}
}
We obsoleted a number of OnMeasure methonds in net9
OnAppearing should still work Can you attach a repro?
We have a bunch of tests that would be failing right now if OnAppearing stopped working
I tested this now again in .NET MAUI 9.0 RC1, and OnAppearing indeed seems to be working now fine. There was some problem there in Preview 2, but it seems to have been fixed now. I will close the issue.