Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF User-controls
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 20-Jun-11 12:44pm
Edited 20-Jun-11 12:48pm
v2
Comments
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
good
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; };
    dp.Children.Add(btnOK);
    
    popupWindowwindow.PlacementTarget = parent;
    popupWindowwindow.Placement = PlacementMode.Center;
    popupWindowwindow.IsOpen = true;
    
}

Thanks
Derin
  Permalink  
Comments
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 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 20 Jun 2011
Copyright © CodeProject, 1999-2014
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