Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to open another user control and close open user control in wpf
Posted
Comments
Sergey Alexandrovich Kryukov 24-Dec-15 13:35pm    
For controls, there are no such concepts as "open" and "close". The question makes no sense.

As you try to operate concepts which don't exist, I cannot really know what you really want to do, but it's very likely that you simply want to remove one control and replace it with another one. All question is: where? Alternatively, you can simply hide one control and show another one.

—SA
kushal mankad 26-Dec-15 8:48am    
yes sergey you understand my question.
i try it but code is execute but user controls not hide.

1 solution

Please see my comment to the question.

As you try to operate concepts which don't exist, I cannot really know what you really want to do, but it's very likely that you simply want to remove one control and replace it with another one. All question is: where? Alternatively, you can simply hide one control and show another one.

The approach with hiding/showing would be the simplest and perhaps more suitable, especially if you have limited number of such controls. This is how:
UIElement.IsVisible Property (System.Windows)[1],
UIElement.Visibility Property (System.Windows)[2].

To add and remove controls, you need too learn something. First of all, you don't just add control; you have to add it to certain parent element, into some point of your logical tree. Please see:
Trees in WPF[1],
Trees in WPF[2],
Trees in WPF[3],
WPF Content Model[4],
WPF Content Model[5],
WPF Content Model[6].

You don't need to dig in all the detail at once; at first, you only need to grasp the main ideas. Look at the last too links. They describe two major cases you may face with (too bad you did not tell us where your controls should be). In first case, your control is the only element of its parent element, its Content. So, typically, you assign the property Content of your parent element with one control instance of another; the types of those different controls can also be different; it should understand it from the content model fundamentals.

There are other cases, you can read about them on the same MSDN page.

The other cases are "Controls That Contain a Collection of Arbitrary Objects". Then you remove one item from collection and add another one to the same collection. Most typical case is the class ItemsControl.

…And so on. I cannot and don't want to list all cases here; it's done very nicely on the page I referenced. You just need to get the idea.

—SA
 
Share this answer
 
Comments
kushal mankad 24-Dec-15 22:41pm    
actually i am using ribbon control. i am using user control instead of window or page. i am switching user control click on ribbon menu items.
My case is. i want to redirect other user control when i clicking on mousedoubleclick. Hope you are understand what i mean to say.(WPF)
Sergey Alexandrovich Kryukov 24-Dec-15 22:54pm    
Yes, more or less. And I hope you understand my answer. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900