Click here to Skip to main content
11,789,706 members (63,376 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WPF User-controls

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 what are the alternatives, if any using UserControl or something else.

Thanks for your help in advance.

Posted 20-Jun-11 11:44am
Edited 20-Jun-11 11:48am
Mark Salsbery at 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.
Member 8008832 at 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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; };
    popupWindowwindow.PlacementTarget = parent;
    popupWindowwindow.Placement = PlacementMode.Center;
    popupWindowwindow.IsOpen = true;

Member 8008832 at 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)

  Print Answers RSS
0 OriginalGriff 999
1 Maciej Los 765
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 430

Advertise | Privacy | Mobile
Web01 | 2.8.1509028.1 | Last Updated 20 Jun 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100