-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Control.SizeChanged Event #9307
Conversation
I may be totally wrong, but from what I've seen in OxyPlot, maybe |
@jp2masa You might be right. However, I'm not entirely sure either. Hopefully one of the core maintainers can clarify. This follows past direction in the linked discussion though. Edit: Bounds is the equivalent of WPF's ActualHeight/Width. Actualheight/Width changes raise this property in WPF. Therefore, watching for bounds changes should be enough. ActualHeight/Width and Bounds properties better reflect the actual state of the control and take into account any transforms -- if they don't I would say there is a bug in Bounds calculation. |
You can test this PR using the following package version. |
> I may be totally wrong, but from what I've seen in OxyPlot, maybe `TransformedBounds` needs to be considered here?
From my understanding, |
On second thought, we want to care about performance here too. This event really isn't needed on other types and making it as high up the inheritance chain as possible is a good thing. My own personal goal is WPF/WinUI compatibility so we should be ok with things as they are. |
This matches WPF and making it bubble was a mistake.
You can test this PR using the following package version. |
You can test this PR using the following package version. |
Why do you need ReactiveUI otherwise? Only inconvenience was that developer need to handle property changed event and filter by property. Which isn't intuitive for developers who came from WPF/UWP. |
You don't need it. But in ReactiveUI it's fast and easy to hookup to the property changed event. If you aren't using ReactiveUI it's even more of a pain. The event is much nicer overall for those of us with apps using older patterns.
Yes, this is much less of a problem for derived controls where you can override the internal OnPropertyChanged method. However, if you are hooking up to a user control template part and updating things internally a size change event is much easier to use. |
You can test this PR using the following package version. |
/// Initializes a new instance of the <see cref="SizeChangedEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="routedEvent">The routed event associated with these event args.</param> | ||
public SizeChangedEventArgs(RoutedEvent? routedEvent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if these events should have internal ctor. Like it was discussed here #8860
But either way it's not important right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That conversation doesn't make sense to me. There is little harm in having these public -- this API isn't going to change. More though, how are apps supposed to implement this event themselves if constructors are private? I never understood why you are hiding constructors.
You can test this PR using the following package version. |
What does the pull request do?
Adds a Control.SizeChanged event.
What is the current behavior?
There is no size changed event and apps must listen directly to Bounds property changes. This isn't optimal for those with existing WPF/UWP/WinUI code and those that aren't heavily using ReactiveUI.
What is the updated/expected behavior with this PR?
There is now a Control.SizeChanged event which is the equivalent to WPF's FrameworkElement.SizeChanged.
NOTE
In Avalonia this event could probably go much lower and be on Layoutable or Visual. However, I kept it on Control which is the equivalent for FrameworkElement.
How was the solution implemented (if it's not obvious)?
Size
for the NewSize/PreviousSize properties instead ofRect
that is used by the Bounds property in Avalonia. This is for two reasons (1) compatibility with WPF and (2) it ensures the event args are sufficiently generic to be used in other places.Checklist
[ ] Added unit tests (if possible)?[ ] Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with user documentationBreaking changes
None
Obsoletions / Deprecations
None
Fixed issues
Closes #9311
Relates to the discussion #8473