|
Good grief. I have no idea what you're talking about. I had an inkling that this had to do with WPF, so I guess that is a small saving grace. None-the-less, I will attempt to understand that article, since I am now learning by fire some WPF.
Hope that makes it all clear as mud.
Oh boy.
Marc
Latest Article - Merkle Trees
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|
|
I thought you were either talking about bitcoin or a nice recipe. Summer has arrived where I live so now I am disappointed.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
While Blend behaviors are very popular because of their ease of use, most people tend to make a fundamental mistake with them because they forget that they were introduced for Silverlight and, when they use them in WPF, they make a fundamental mistake. Let's see if you know what it is (hint, it's about event handlers).
This space for rent
|
|
|
|
|
You may be thinking about two possibilities:
a) Traditional event handlers use tight coupling. Something you want to avoid in MVVM. To avoid this, I use a weak event manager inside the behavior, like so:
WeakEventManager<TextBox, RoutedEventArgs>.AddHandler(this.AssociatedObject, "Loaded", setFocus);
b) These behaviors get passed UI elements. In the example above it gets passed a TextBox. This may never happen if the behavior is part of a ViewModel, but I believe it is OK, because the behavior is part of the View, not the ViewModel.
Did you have one of these issues in mind?
Get me coffee and no one gets hurt!
|
|
|
|
|
No, the one I was thinking of was where people tend to disconnect their event handlers in Blend. The number of people I have seen using OnDetaching to handle removing events inside Blend is unbelievable. This method was introduced to support Silverlight and is of no real use in WPF which doesn't actually call it. The problem is, when the containing element is removed the OnDetaching method isn't called, potentially leaking memory.
This space for rent
|
|
|
|
|
Good to know, thanks! I wonder if this still applies in .net 4.6? I will run a few tests to see if OnDetaching is called. I wonder: If it is not called, how does one prevent memory leaks?
Get me coffee and no one gets hurt!
|
|
|
|
|
Use the AssociatedObject.Unloaded event instead.
This space for rent
|
|
|
|
|
Yes! I just figured it out for myself. Thanks so much for confirming I am on the right path! Upvote coming your way.
Get me coffee and no one gets hurt!
|
|
|
|
|
Pete, I found this interesting article about the Weak Event Manager. I quote:
" Whenever the source object lifetime extends beyond the object lifetime of the listener, the normal event pattern leads to a memory leak: the listener is kept alive longer than intended.
The weak event pattern is designed to solve this memory leak problem. The weak event pattern can be used whenever a listener needs to register for an event, but the listener does not explicitly know when to unregister."
It seems with the Weak Event Manager one does not need to be concerned so much about memory leaks?
Weak Event Manager[^]
Get me coffee and no one gets hurt!
|
|
|
|
|
This is sort of true. And yes, I have done a fair bit with this. The basic problem is that the weak event handler doesn't have a deterministic end point - in other words, it could still receive notifications after you think the object has gone out of scope. When it gets collected is entirely down to the GC, so you could have event handling going on unnecessarily past the point you think you're done with it. I've seen occasions where a VM is still receiving notifications after I thought it was out of scope, leading to some interesting memory spikes. In general, if you can control the lifetime of an event, you're better off doing that - this is a philosophy that I've stuck to in the 10 odd years I've been doing WPF.
This space for rent
|
|
|
|
|
Thanks for the good advice!
Get me coffee and no one gets hurt!
|
|
|
|
|
In trying to start VS I accidentally clicked the Blend icon (because they're identical - ya THAT was a great idea), and 20 minutes later Blend finally appeared so I could close it. All the while a tray notification was up saying "Microsoft Blend is busy...".
And I'm sitting there thinking "DOING WHAT THAT TAKES 20 MINUTES FOR CRYING OUT LOUD!!!"
WTF could Blend POSSIBLY be doing that takes 20 minutes to load???
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Blending your personal information with the data on the cloud servers, maybe?
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
They really aren't identical - the symbols are different, as are the colours. If it's your first time in Blend, it does a lot of configuration initially.
This space for rent
|
|
|
|
|
The colours(colors) (FTFY ) are identical, but the Blend icon has a little 'B' in it, which is WAAAAY to small for an old guy like me to see.
Not my first time opening it.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Oh, you're still using 2015 then. There's a lot of network traffic goes on in that version of the Visual Studio "suite".
This space for rent
|
|
|
|
|
The colours(colors) (FTFY )colours (FTBFY).
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
There is a site that will tell you: Will It Blend?[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I just noticed that Outlook will provide spelling suggestions for Bluetooth, Arduino, and Samsung, Linux and Ubuntu, but if you put in macOS you get nothing.
Really?
cheers
Chris Maunder
|
|
|
|
|
Chris Maunder wrote: but if you put in macOS you get nothing.
Odd, why does it not suggest maco?
|
|
|
|
|
I thought this was funny.
|
|
|
|
|
Heh - thanks. The humor was aimed at academics and intellectuals - people like you and me.
|
|
|
|
|
Nish Nishant wrote: The humor was aimed at academics and intellectuals - people like you and me.
I didn't get the joke, and now I know why.
|
|
|
|
|
Chris Maunder wrote: if you put in macOS you get nothing. I agree.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|