我使用此代码创建Mahapps自定义对话框消息。问题是对话框窗体没有显示关闭按钮,所以无法关闭它。 如何显示关闭按钮?
public async void button_Click(object sender, RoutedEventArgs e)
{ Button btn = (Button) sender;
//dialog.Resources["CustomDialogTest"];
string[] id = btn.Name.ToString().Split('_');
this.MetroDialogOptions.ColorScheme = MetroDialogColorScheme.Accented;
var dialog = (BaseMetroDialog)this.Resources["CustomDialogTest"];
var mySettings = new MetroDialogSettings()
{
AffirmativeButtonText = "OK",
AnimateShow = true,
NegativeButtonText = "Go away!",
FirstAuxiliaryButtonText = "Cancel",
};
await this.ShowMetroDialogAsync(dialog);
// this for close the dialog -> await this.HideMetroDialogAsync(dialog);
}
答案 0 :(得分:3)
我需要一个自定义输入对话框。因此,我创建了一个继承自CustomInputDialog
。{/ p>的BaseMetroDialog
类
我使用此代码调用方法:
public async Task<string> ShowCustomDialog(string message, string title)
{
var metroDialogSettings = new MetroDialogSettings()
{
AffirmativeButtonText = "OK",
NegativeButtonText = "CANCEL",
AnimateHide = true,
AnimateShow = true,
ColorScheme = MetroDialogColorScheme.Accented,
};
var dialog = new CustomInputDialog(View, metroDialogSettings)
{
Message = message,
Title = title,
Input = metroDialogSettings.DefaultText
};
return await InvokeOnCurrentDispatcher(async () =>
{
await View.ShowMetroDialogAsync(dialog, metroDialogSettings);
await dialog.WaitForButtonPressAsync().ContinueWith((m) =>
{
InvokeOnCurrentDispatcher(() => View.HideMetroDialogAsync(dialog));
});
return dialog.Input;
});
}
Message,Title和Input是CustomInputDialog的依赖项属性。这在我的最后工作。
答案 1 :(得分:2)
在对话框中添加关闭按钮(位于Resources
)&amp;挂钩其Click
事件以关闭对话框。要结束,请使用this.HideMetroDialogAsync(dialog);
this
为MetroWindow
个实例。