貴DialogViewmodel實現IDialogResultVMHelper?並且你的View/DataTemplate有一個綁定到你的DialogViewmodel的命令來引發RequestCloseDialog?
如
public class DialogViewmodel : : INPCBase, IDialogResultVMHelper
{
private readonly Lazy<DelegateCommand> _acceptCommand;
public DialogViewmodel()
{
this._acceptCommand = new Lazy<DelegateCommand>(() => new DelegateCommand(() => InvokeRequestCloseDialog(new RequestCloseDialogEventArgs(true)),() => **Your Condition goes here**));
}
#region Implementation of IDialogResultVMHelper
public event EventHandler<RequestCloseDialogEventArgs> RequestCloseDialog;
private void InvokeRequestCloseDialog(RequestCloseDialogEventArgs e)
{
var handler = RequestCloseDialog;
if (handler != null)
handler(this, e);
}
#endregion
}
在對話框控制的任何地方:
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" MinHeight="30">
<Button IsDefault="True" Content="Übernehmen" MinWidth="100" Command="{Binding AcceptCommand}"/>
<Button IsCancel="True" Content="Abbrechen" MinWidth="100"/>
</StackPanel>
,然後你的結果應該在您的視圖模型
var dialog = new DialogViewmodel();
var result = _dialogservice.ShowDialog("My Dialog", dialog);
if(result.HasValue && result.Value)
{
//accept true
}
else
{
//Cancel or false
}
謝謝合作!這很好用!另外我介紹了Lazy-Loading的世界! – bdan 2014-09-12 00:38:27