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
Rename dialog - select all text in textbox when loading #3091
Conversation
So, what you've done here is provided an anonymous (unnamed) function that gets called by the base class when the view is loaded. (Otherwise known as a delegate or callback). Is there a specific thing you don't understand? |
@retailcoder @Hosch250 my MVVM is rusty. Is there a way to accomplish this outside of the code behind? |
@rubberduck203 haven't seen the code yet, but IMO that's strictly a presentation concern, it has nothing to do in the ViewModel - it actually belongs in the View :) |
@@ -5,6 +5,12 @@ public partial class RenameView | |||
public RenameView() | |||
{ | |||
InitializeComponent(); | |||
|
|||
base.Loaded += delegate |
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.
You could remove the delegate
keyword here, C# is clever enough to infer it :-)
The problem with anonymous handlers is that when the event provider is destroyed, there's no way to de-register the handler; if the event provider wasn't the same object that registers the event, this would be a memory leak (the handler is holding on to a reference that's otherwise eligible for garbage collection. Doesn't apply in this case, but definitely worth understanding.
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 line is where I was confused. Found it on the interwebs lol. IntellSense told me what base
is, but no idea what delegate
is or +=
does.
I understand everything in the second paragraph, but what an "anonymous" handler is. I'll probably get the answer to that this holiday weekend as I work though as much C# tutorials as I can handle. :)
Edit: I think I get it... maybe.
Not sure, but can't you do this in the XAML? |
@Hosch250 I would have thought so... but I didn't find any method or property to do it. YMMV. |
I don't think you can. But, this does need to be presentation-only. It should go in the code-behind (the .xaml.cs file). |
@Hosch250 Um... Isn't that where I put it? |
Yeah, I was just making a random comment. Remove the |
removed redundant delegate keyword & base qualifier
fixed stupid compile error introduced in previous in-browser edit
I admit that I don't understand how this works...
But eventually I will learn enough to understand.
Closes #3090