C# WPF Registered names

by on Jul.18, 2011, under Coding

I was working on a project that was using Registered names on a WPF Form for paths so that the user can select them, over all it was working quite well, until the user was required to delete some on them (in random order)

After a small bit of tweaking, I also got that working.  Though it did bring up another issue.  When I wanted to Clear the canvas, their was no easy way to also clear all the left over Registered names on the existing paths, and not every path had a registered name.

My final solution was to come up with this small routine.  It at least appear to do the job.



        private void ClearRegisteredNames(Canvas CanvasToClear)
            if (CanvasToClear != null)
                foreach (object ChildObject in LogicalTreeHelper.GetChildren(CanvasToClear))
                    Type Name = ChildObject.GetType();
                    if (Name == typeof(Path))
                        // Get Path Name if Any?
                        Path FoundPath = (Path)ChildObject;
                        string PathName = FoundPath.Name;
                        if (PathName != "") CanvasToClear.UnregisterName(PathName);

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!