模拟MessageBox.Show()

时间:2013-08-16 09:48:01

标签: c# wpf xaml messagebox

我正在WPF(c#)中编写程序。我住在伊朗所以我的语言是波斯语(right to left)。我想使用更多按钮或其他控件制作自定义MessageBox

我使用简单的Window来显示消息。在MessageBox显示的C#中,用户无法单击或对其他窗口执行任何操作。我怎能在窗口simulate这个?

在上一篇文章中,我使用了WPFCustomeMessageBox库。请不要把它转介给我。

3 个答案:

答案 0 :(得分:3)

使用.ShowDialog()显示模式对话框:

MyMsgBox.ShowDialog()

这将停止执行,直到消息框关闭。请参阅MSDN Documentation

答案 1 :(得分:1)

使用Window.Showdialog并且不要忘记设置Window Parent,否则你会得到有趣的行为。

然后在Window类中具有预期返回的属性,这些属性由对话框的结果填充。 像:

public void testDialog()
{
var return = new DialogModelReturn();
mywindow.ShowDialog(new DialogModel(return));

if (return.isOk)
{
}

}

这种思路应该有所作为。 另外:我建议将WindowStyle设置为none,或者至少只设置一个关闭Button,以获得“ModalDialog感觉”。

像这样:

<Window x:Class="bla.bla"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Fortschritt" Icon="bla.png" Height="200" Width="600"
        WindowStyle="None" Background="RoyalBlue">

答案 2 :(得分:1)

编辑:我似乎没有仔细阅读这个问题,并认为问题是无法在MessageBoxes中使用从右到左对齐(这可以通过MessageBoxOptions)。


MessageBox.Show()方法存在重载,允许您指定MessageBoxOptions。其中一些选项涉及从右到左的对齐。

我不知道伊朗使用的语言,所以你必须尝试使用​​自己的文本,但这里是如何指定选项(方法的最后一个参数):

string message = "Test message.";
string caption = "RTL Test";
MessageBoxImage image = MessageBoxImage.Information;
MessageBoxButton button = MessageBoxButton.OK;
MessageBoxResult defaultResult = MessageBoxResult.OK;

MessageBox.Show(message, caption, button, image, defaultResult, MessageBoxOptions.RightAlign);
MessageBox.Show(message, caption, button, image, defaultResult, MessageBoxOptions.RtlReading);
MessageBox.Show(message, caption, button, image, defaultResult, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);

以下是有关选项的MSDN文章的链接:MessageBoxOptions Enum (Winforms)

相关问题