1

在複合應用程序(棱鏡),當我的模塊加載,我得到這個錯誤:如何讓Prism/Unity自動解析視圖(UserControl)?

{"The current build operation (build key Build Key[CustomersModul.ViewModels.CustomerAllViewModel, null]) failed: The parameter view could not be resolved when attempting to call constructor CustomersModul.ViewModels.CustomerAllViewModel(CustomersModul.Views.CustomerAllView view). (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)"}

解決這個類:

CustomerAllViewModel layoutManager = this.container.Resolve<CustomerAllViewModel>(); 

而該類看起來像

public class CustomerAllViewModel : ViewModelBase 
{ 
    public CustomerAllView View { get; set; } 
    public ICommand TextChangeCommand { get; set; } 
    private Customer customer; 

public CustomerAllViewModel(CustomerAllView view) 
{ 
    View = view; 
    view.DataContext = this; 
    ... 

通常我會解析演示者,它們沒有構造函數參數並在內部實例化它們的視圖。這是我第一次使用接受View作爲參數的ViewModel。有趣的是,當我轉到resharper的視圖時,它詢問我是否想要轉到XAML或後面的代碼,所以也許棱鏡正在弄糊塗哪一個實例化?

如何讓Prism在參數中自動實例化此視圖(帶有XAML和代碼隱藏的UserControl)?

+0

這是怎麼回事? – 2009-09-14 03:20:25

回答

4

有時候這實際上不是錯誤,而是其他的東西。查看內部異常,或者調用Microsoft.Practices.Composite.ExceptionExtensions.GetRootException(ex)來獲取根異常。你很可能會發現在你沒有看到的構造函數中有一些錯誤。

0

您是否已將CustomerAllView添加到容器?當我忘記爲容器添加類型時,通常會出現此錯誤。