-1

I'm quite new in C# WPF. I want my Popup control to be positioned in a certain coordinates of the user's screen. and I want to make my textblock text center in the textblock itself. I tried to add a block but it doesn't work. Look at my XAML codes: (I'm 97% done in my personal project. :) )

Also, look at my screenshot, I put a red box there, I want my popup control to be there, although it is not my priority cause the original position is quite fine with me, but I would be glad if this will be moved.

Next, look at the annoying text, it is not centered. The current position of the popup is in the left most and upper most part of my screen.

<Window x:Class="KeyLocks_Notifier.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Popup Name="Popup1" AllowsTransparency="True" PlacementRectangle="0,0,30,50" Placement="Center"
          PopupAnimation="Fade">
            <Border BorderBrush="{x:Null}" Height="50">
            <TextBlock Name="myPopupText"
                 Background="#FF9700FF"
                 Height = "40"
                 Width="180"
                 Foreground="White" FontWeight="Bold" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock.Effect>
                    <DropShadowEffect/>
                </TextBlock.Effect>
            </TextBlock>
            </Border>
        </Popup>
    </Grid>
</Window>
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95

1 Answers1

1

On the window : In XAML there is a WindowStartupLocation on the root level with 3 options (Manual, CenterScreen, CenterOwner)

If you want a custom Location on your screen you need to set WindowStartupLocation to Manual and set the Top & Left with pixel

For your popup : You can set the Placement to custom

Example Here

And for your text position Here

Community
  • 1
  • 1
C1rdec
  • 1,647
  • 1
  • 21
  • 46