Mahapps 1.3对话框和Avalon.Wizard

时间:2016-10-04 13:13:06

标签: c# wpf mahapps.metro

我已将流行的用户界面库MahappsAvalon.Wizard控件集成在一起。

它整合得很好,但我对Mahapps对话框有疑问。 Wizard控件定义了一个 InitializeCommand 来处理向导页面的输入。

显然在初始化附加到View的Dependency属性(DialogParticipation.Register)之前触发InitializeCommand。

这会导致以下错误:

Context is not registered. Consider using DialogParticipation.Register in XAML to bind in the DataContext.

可以重现问题的示例项目here

有关如何解决这个问题的任何建议吗?

1 个答案:

答案 0 :(得分:3)

页面Xaml不是在initialize命令中创建的,所以此时你不能使用DialogCoordinator。

这是一个带有LoadedCommand的自定义界面,您可以在ViewModel上实现并在后面的Xaml代码中调用它。

import commands
import string
import os
(status, output) = commands.getstatusoutput("(g++ test/*.c -O3 -lquadmath -m64)")

ViewModel:

public interface IWizardPageLoadableViewModel
{
    ICommand LoadedCommand { get; set; }
}

观点:

public class LastPageViewModel : WizardPageViewModelBase, IWizardPageLoadableViewModel
{
    public LastPageViewModel()
    {
        Header = "Last Page";
        Subtitle = "This is a test project for Mahapps and Avalon.Wizard";

        InitializeCommand = new RelayCommand<object>(ExecuteInitialize);
        LoadedCommand = new RelayCommand<object>(ExecuteLoaded);
    }

    public ICommand LoadedCommand { get; set; }

    private async void ExecuteInitialize(object parameter)
    {
        // The Xaml is not created here! so you can't use the DialogCoordinator here.
    }

    private async void ExecuteLoaded(object parameter)
    {
        var dialog = DialogCoordinator.Instance;
        var settings = new MetroDialogSettings()
        {
            ColorScheme = MetroDialogColorScheme.Accented
        };
        await dialog.ShowMessageAsync(this, "Hello World", "This dialog is triggered from Avalon.Wizard LoadedCommand", MessageDialogStyle.Affirmative, settings);
    }
}

希望这有帮助。

enter image description here

enter image description here