user9152389
user9152389

Reputation:

How can i set parent to popup

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.

Upvotes: 0

Views: 1134

Answers (2)

Karthik
Karthik

Reputation: 11

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;      
 }   

Upvotes: 1

Daniele Sartori
Daniele Sartori

Reputation: 1703

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

Upvotes: 0

Related Questions