小编ghe*_*eff的帖子

WPF,MVVM和PRISM - 为此对象定义的无参数构造函数

回答 OK,所以添加E-Bat给出的建议代码没有任何影响,直到我开始一个新项目并逐字复制所有代码.我只能假设在http://prismlibrary.com/上的ViewModelLocator中必须有一些后台代码,它们没有更新以考虑无参数构造函数.希望这可以帮助其他人解决同样的问题

原始问题 我使用棱镜设置了一个MVVM项目.我有一个MainWindow.xaml和5个视图; 我正在使用的ButtonsView,HeaderView,ProcessInputView,ProcessLogView和ProcessSelectionView,每个View都有一个关联的ViewModel.

MainWindow.xaml

<Window x:Class="TransactionAutomationTool.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:TransactionAutomationTool"
    xmlns:views="clr-namespace:TransactionAutomationTool.Views"
    xmlns:prism="http://prismlibrary.com/"
    prism:ViewModelLocator.AutoWireViewModel="True"
    mc:Ignorable="d"
    Title="MainWindow" Height="600" Width="800">
<Grid>
    <views:HeaderView x:Name="HeaderViewControl" Margin="20,21,0,0" />
    <views:ProcessSelectionView x:Name="ProcessSelectionViewControl" Margin="20,119,0,0" />
    <views:ProcessInputView x:Name="ProcessInputViewControl" Margin="20,280,0,0" />
    <views:ProcessLogView x:Name="ProcessLogView" Margin="298,105,0,0" />
    <views:ButtonsView x:Name="ButtonViewControl" Margin="0,513,0,0" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

MainWindowViewModel

public class MainWindowViewModel: BindableBase
{

    public IEventAggregator _events;
    private UserPrincipal userPrincipal;
    public MainWindowViewModel(IEventAggregator events)
    {
        _events = events;
        userPrincipal = UserPrincipal.Current;
        _events.GetEvent<HeaderLoaded>().Subscribe(HeaderHasBeenLoaded);

    }

    private void HeaderHasBeenLoaded()
    {
        _events.GetEvent<UserNameUpdate>().Publish(string.Format("{0} {1}", userPrincipal.GivenName, userPrincipal.Surname));
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试在设计模式下查看MainWindow时,我在设计模式下获得以下错误 的MainWindow屏幕截图 …

c# wpf xaml prism mvvm

4
推荐指数
2
解决办法
2659
查看次数

标签 统计

c# ×1

mvvm ×1

prism ×1

wpf ×1

xaml ×1