first post. So first off, thanks for all the help over the years as I’ve learned from the sidelines. I just have a rather specific code-design question that I couldn’t find elsewhere.
I have a series of storyboards (among other things,) that relate to specific FrameworkElements, that need to be generated in the code, and I feel that it’s either a little messy, and possibly a little slow (thought I haven’t tested) to store a dictionary with the FrameworkElement – Storyboard relationships, to lookup on the fly.
private static Dictionary<FrameworkElement, Storyboard> storyboardMapping;
private void FrameworkElement_SizeChanged(object sender, SizeChangedEventArgs e)
{
FrameworkElement fe = sender as FrameworkElement;
Storyboard sb = null;
if(storyboardMapping.TryGetValue(fe, out sb))
{
sb.Begin();
}
// etc
}
Having just considered using (private) Attached Dependency Properties instead, does anyone have an opinion on whether one is faster/cleaner than the other? The other downside I see to using Dictionaries, is that they also don’t work well with WeakReferences. Not being a C# Guru, I don’t completely understand whether that creates issues with Garbage Collection.
Also, I’m not exactly sure how big this Dictionary could get. Possibly up to 400 objects or even more?
Rather than using either, I am now using the
.Resourcesproperty of UIElements which is a much more appropriate place to store these.This question was previously answered, however the answer seems to have disappeared. As such I will mark this answer as the correct one unless the original reappears…