Skip to content
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

Merged
merged 4 commits into from Jun 29, 2017
Merged

Rename dialog - select all text in textbox when loading #3091

merged 4 commits into from Jun 29, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 28, 2017

I admit that I don't understand how this works...

But eventually I will learn enough to understand.

Closes #3090

@ghost ghost changed the title select all text in textbox when loading Rename dialog - select all text in textbox when loading Jun 28, 2017
@rubberduck203
Copy link
Member

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?

@rubberduck203
Copy link
Member

@retailcoder @Hosch250 my MVVM is rusty. Is there a way to accomplish this outside of the code behind?

@retailcoder
Copy link
Member

@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
Copy link
Member

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.

Copy link
Author

@ghost ghost Jun 29, 2017

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.

@Hosch250
Copy link
Member

Not sure, but can't you do this in the XAML?

@ghost
Copy link
Author

ghost commented Jun 29, 2017

@Hosch250 I would have thought so... but I didn't find any method or property to do it. YMMV.

@Hosch250
Copy link
Member

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).

@ghost
Copy link
Author

ghost commented Jun 29, 2017

It should go in the code-behind (the .xaml.cs file).

@Hosch250 Um... Isn't that where I put it? RetailCoder.VBE/UI/Refactorings/Rename/RenameView.xaml.cs

@Hosch250
Copy link
Member

Yeah, I was just making a random comment. Remove the delegate keyword and it looks good to go.

removed redundant delegate keyword & base qualifier
fixed stupid compile error introduced in previous in-browser edit
@retailcoder retailcoder merged commit 4dcc4f2 into rubberduck-vba:next Jun 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants