0

I want to show user information when click user icon like=>

enter image description here

Firstly i am new with wpf design and after little researched I though i can do with popup. so i was try with popup.But problem is popup box are provides a way to display content in a separate window (MSDN) So when i change size of parent window or minimize the parent window,It's not effect to popup.Popup placement are always fix.

So please let me known popup is the only way of my requirement and if have any other please let me known.

  • What is the question exactly? `Popup` size and [position](https://stackoverflow.com/q/1600218/1997232) can be adjusted (binding with converter to PlacementTarget) if that is the question. Or maybe you don't need `Popup`, rather an element on top in visual tree, this way it will automatically participate in layouting. – Sinatr Jan 25 '18 at 09:59
  • @Sinatr I am interested about "binding with converter to PlacementTarget".Please can u show me some example link.Thanks –  Jan 25 '18 at 10:07
  • 1
    [Here](https://stackoverflow.com/q/38709950/1997232) is resizing. [Here](https://stackoverflow.com/q/20326744/1997232) is converter (to add offset, scale, whatever to actual value). – Sinatr Jan 25 '18 at 10:07
  • Thanks you i will check it. –  Jan 25 '18 at 10:13

2 Answers2

1

There are two events for windows Activated and Deactivated

Activated - https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.activated?view=net-5.0

Deactivate - https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.deactivated?view=net-5.0

when mainwindow is out of focus Deactivated event is triggered, here set that popup.IsOpen to false and once mainwindow is focused Activated event is triggered set Popup.IsOpen to true.

Example:

Private Popup myPopup;
public Constructor()
{
      myPopup = new Popup();

      TextBlock textContent = new TextBlock();
      textContent.Text = "Here is my Code";

      myPopup.Child =  textContent; 

      System.Windows.Application.Current.MainWindow.Activated += ActivatePopupWindow;
      System.Windows.Application.Current.MainWindow.Deactivated += DeActivatePopupWindow;
}

 private void DeActivatePopupWindow(object sender, EventArgs e)
 {
      myPopup.IsOpen = false;     
 }

 private void ActivatePopupWindow(object sender, EventArgs e)
 {
      myPopup.IsOpen = true;      
 }   
Karthik
  • 11
  • 2
0

You can build your window to have an Expander in a place where you like it (for instance under the picture). The expander itself will be the button that will open this extra section containing your infos.

   <Expander>
        <Grid ...>
            <Grid.RowDefinitions>
                ....
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                ...
            </Grid.ColumnDefinitions>
            //put your content here
        </Grid>
    </Expander>

you can use also set the TemplateProperty of the expander to attach to it some animation when it opens.

The expander is a control that "hide" a portion of your window until it's toggled and you can place inside it anything you want. You don't need the popup unless it's really what you want

Daniele Sartori
  • 1,674
  • 22
  • 38
  • I am little confuse,Can i overflow expander when expand? –  Jan 25 '18 at 10:12
  • i don't get your question. However it seemed to me that you din't particulary liked the fact that the popup is another window (with all the problems that must be handled by this fact). The expander is a simple solution and avoid your concerns, cause it's part of the window where it is placed, and so the resize and the drag are't a problem – Daniele Sartori Jan 25 '18 at 10:15
  • Please can you show me some example link? I just see expandar is [link](https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/expander-overview) may be i don't understand well your answer.Thanks –  Jan 25 '18 at 10:29
  • 1
    https://wpftutorial.net/Expander.html , https://www.codeproject.com/Articles/248112/Templating-WPF-Expander-Control .... it's just another way to show that extra information you want to show without the need to use a popup. You can insert there what you want – Daniele Sartori Jan 25 '18 at 10:32
  • Ohh.I see.Thanks you for your link. –  Jan 26 '18 at 01:14