Use MessageBox to display a dialog box that appears in the caller's central, obviously, to do this, MessageBox must get the parent control, so as to calculate the center position.
I have a similar problem in a page where clicking the button displays a popup, and set the page's property IsEnable to false, therefore, code must get the parent control --- page, but I do not know can not do so.
example:
namespace WpfBrowserApplication1
{
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessagePopup.Show(this,"hello");
}
}
}
namespace WpfBrowserApplication1
{
public sealed class MessagePopup
{
public static void Show(UIElement parent, string message)
{
Popup window = new Popup();
StackPanel sp = new StackPanel { Margin = new Thickness(5) };
sp.Children.Add(new TextBlock { Text = message });
Button newButton = new Button { Content = "button" };
newButton.Click += delegate { window.IsOpen = false; parent.IsEnabled = true; };
sp.Children.Add(newButton);
sp.Children.Add(new Slider { Minimum = 0, Maximum = 50, Value = 25, Width = 100 });
window.Child = new Border
{
Background = Brushes.White,
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(2),
Child = sp
};
window.PlacementTarget = parent;
window.Placement = PlacementMode.Center;
window.IsOpen = true;
parent.IsEnabled = false;
}
}
}
I hope that the parent is get by code , not by parameters,like this:
public static void Show(string mess)
{
UIElement parent =
...
parent.IsEnable = false;
}
Thanks.