I want to have control of where MessageBoxWpf is displayed.
Center of screen would be adequate.
The problem that it always displays in the upper-left.
<UserControl x:Class="LatestAlarm3.MessageBoxWpf"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LatestAlarm3"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Popup Name="myPopup" IsOpen="False" HorizontalAlignment="Center" VerticalAlignment="Center" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=Window}}">
<Border BorderThickness="1">
<StackPanel>
<TextBlock Name="myPopupText" Background="LightBlue" Foreground="Blue" Padding="30">
Popup Text
</TextBlock>
<StackPanel Orientation="Horizontal">
<Button Click="ButtonOK_Click">OK</Button>
<Button x:Name="myPopupCancelButton" Click="ButtonCancel_Click">Cancel</Button>
</StackPanel>
</StackPanel>
</Border>
</Popup>
</UserControl>
public static LatestAlarm3.DialogResult Show(string text, string caption)
{
_messageBoxWpf = new MessageBoxWpf();
//this.Owner = Application.Current.MainWindow;
//this.WindowStartupLocation = WindowStartupLocation.CenterOwner;
//_messageBoxWpf.myPopup.PlacementTarget = uIElement;
_messageBoxWpf.myPopupText.Text = text;
_messageBoxWpf.myPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Center;
_messageBoxWpf.myPopupCancelButton.Visibility = Visibility.Collapsed;
_messageBoxWpf.myPopup.IsOpen = true;
return _dialogResult;
}