You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a ContentView where I like to inform the UI about Property-Changed when I switch my theme for example.
I'm pretty sure it works in Xamarin but now not in Maui .net9 anymore?!
For example I have this base class
public class SettingsCellViewBase : ContentView
{
public SettingsCellViewBase()
{
WeakReferenceMessenger.Default.Register<ThemeChangedMessage>(this, (o, msg) =>
{
OnPropertyChanged();
});
}
...
used like this for example:
public partial class SettingTextRadialProgressCell : SettingsCellViewBase
{
protected override void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == SettingTextCell.IsEnabledProperty.PropertyName)
{
OnPropertyChanged(nameof(TextColor));
}
}
public Color TextColor => this.IsEnabled
? _theme.GetColor(BaseTheme.ColorName.TextOnBackgroundColor)
: _theme.GetColor(BaseTheme.ColorName.DisabledTextOnBackgroundColor);
public static readonly BindableProperty TextProperty = BindableProperty.Create(
nameof(Text), typeof(string), typeof(SettingTextRadialProgressCell), string.Empty);
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
... and other properties ...
Now my Message is send and received
the OnPropertyChanged(); is called
but in the protected override void OnPropertyChanged... I only get:
"BackgroundColor" once
".ctor" once
and that's it.
".ctor" I can understand - the OnPropertyChanged() is called without a name and so the [CallerName] ist used which might be correctly the Constructor in this case
So I've tried OnPropertyChanged(string.Empty) too:
got once "BackgroundColor"
got once "" (an empty string)
That's it
Calling OnPropertyChanged(null) causes some exception then
So:
Is OnPropertyChanged not suitable for informing every property of that class?
Is this a Bug and is there a Workaround?
Or is this intended and how should I inform all properties now?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a ContentView where I like to inform the UI about Property-Changed when I switch my theme for example.
I'm pretty sure it works in Xamarin but now not in Maui .net9 anymore?!
For example I have this base class
used like this for example:
Now my Message is send and received
the
OnPropertyChanged();
is calledbut in the
protected override void OnPropertyChanged...
I only get:and that's it.
".ctor" I can understand - the
OnPropertyChanged()
is called without a name and so the[CallerName]
ist used which might be correctly the Constructor in this caseSo I've tried
OnPropertyChanged(string.Empty)
too:That's it
Calling
OnPropertyChanged(null)
causes some exception thenSo:
Is OnPropertyChanged not suitable for informing every property of that class?
Is this a Bug and is there a Workaround?
Or is this intended and how should I inform all properties now?
I mean, in this article
https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged.propertychanged?view=net-9.0
it says:
But not for ContentView anymore?
Beta Was this translation helpful? Give feedback.
All reactions