Click here to Skip to main content
16,021,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm fairly new to WPF & C#. Would appreciate any help or guidance on this particular question:

I have a class A that extends UserControl. The UserControl has a bunch of data columns.

I need to do the following, but I am not allowed to use the Window object to achieve the result:

1) When a user right clicks the mouse, they should have a MenuItem that when they click that spawns a UserControl (can not be a Window - as this is restricted). The UserControl is just a configuration window where user can do some setting changes.

2) When user double clicks on certain cells in the Main UserControl, same action as (1) - a new dynamic UserControl is spawned on top of the Main UserControl.

Please note that I am able to achieve both the conditions above if I create a new Class that extends Window and from the Main UserControl, I do ClassWindow.Show() - the point is that I am restricted to using Window as an object.....so what are the alternatives, if any using UserControl or something else.

Thanks for your help in advance.

-Manish
Posted
Updated 20-Jun-11 11:48am
v2
Comments
Mark Salsbery 20-Jun-11 18:26pm    
Why the no-Window restriction? Specs? Or something you find restrictive? I assume the popup should behave modally, so do a Bing search on "WPF modal" and you'll find several examples - good and bad - that will at least point you in the right direction.
Manish V Mahajan 21-Jun-11 8:07am    
I would use the Window if I could, but I the functionality has a security restriction from a third party vendor - not sure why, but I am also following up with them on the same. Will take a look @ the Modal and revert if any questions.

Thanks, M

1 solution

I think Popup will be the best option for you.

You can make a popup control and show on top of your main control.
Popup.IsOpen - property will work as Window.Show() - function

public static void Show(UIElement parent, string message)
{
    Popup popupWindow = new Popup();
    
    //Make popup content
    DockPanel dp = new DockPanel();
    dp.Children.Add(new TextBlock() { Text = message });
    Button btnOK = new Button { Content = "OK" };
    btnOK.Click += delegate { popupWindow.IsOpen = false; };
    dp.Children.Add(btnOK);
    
    popupWindowwindow.PlacementTarget = parent;
    popupWindowwindow.Placement = PlacementMode.Center;
    popupWindowwindow.IsOpen = true;
    
}


Thanks
Derin
 
Share this answer
 
Comments
Manish V Mahajan 21-Jun-11 10:37am    
Hi Derin,

Many Thanks for your help. This worked perfectly...the only thing that was missing was to add:

1) popupWindow.Child = dp;
2) Set: popupWindow.Width = 300, popupWindow.Height=300

Cheers man...appreciate the help.

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