C# Caliburn.Micro找不到CustomServiceWModel的视图。这里怎么了?
我正在使用Caliburn.Micro尝试将列表框中的项目绑定到两个视图中的一个视图,而不是单个视图模型。我可以在列表框中显示项目,但当选择任何项目时,我会得到“找不到CustomerServiceWModel的视图” 以下是此应用程序的相关部分: AppBootstrapper:C# Caliburn.Micro找不到CustomServiceWModel的视图。这里怎么了?,c#,wpf,xaml,caliburn.micro,C#,Wpf,Xaml,Caliburn.micro,我正在使用Caliburn.Micro尝试将列表框中的项目绑定到两个视图中的一个视图,而不是单个视图模型。我可以在列表框中显示项目,但当选择任何项目时,我会得到“找不到CustomerServiceWModel的视图” 以下是此应用程序的相关部分: AppBootstrapper: public class AppBootstrapper : BootstrapperBase { public AppBootstrapper() : base() {
public class AppBootstrapper : BootstrapperBase
{
public AppBootstrapper()
: base()
{
Initialize();
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
base.DisplayRootViewFor<CustomerWorkspaceViewModel>();
}
}
public abstract class DocumentWorkspace<TDocument> : Conductor<TDocument>.Collection.OneActive
where TDocument : class, INotifyPropertyChanged, IDeactivate, IHaveDisplayName
{
public enum DocumentWorkspaceState
{
Read,
Edit
}
DocumentWorkspaceState state = DocumentWorkspaceState.Read;
public DocumentWorkspaceState State
{
get { return state; }
set
{
if (state == value)
return;
state = value;
NotifyOfPropertyChange(() => State);
}
}
}
和CustomerWorkspace视图模型:
public class CustomerViewModel : Screen
{
private string name;
public string Name
{
get { return name; }
set
{
name = value;
NotifyOfPropertyChange(() => Name);
}
}
}
public class CustomerWorkspaceViewModel : DocumentWorkspace<CustomerViewModel>
{
private CustomerViewModel selectedItem;
public CustomerViewModel SelectedItem
{
get { return selectedItem; }
set
{
selectedItem = value;
NotifyOfPropertyChange(() => SelectedItem);
}
}
public CustomerWorkspaceViewModel()
{
Items.AddRange(
new ObservableCollection<CustomerViewModel>
{
new CustomerViewModel {Name = "Customer 1" },
new CustomerViewModel {Name = "Customer 2" },
new CustomerViewModel {Name = "Customer 3" }
});
}
}
我的视图/客户文件夹中有四个视图:
在Views/Customers/CustomerWorkspace中,我有“编辑”视图和“读取”视图:
Edit.xaml:
<Grid>
<StackPanel>
<Label Content="Edit View"/>
<TextBlock Foreground="White"
FontSize="20"
Text="{Binding Name}" />
</StackPanel>
</Grid>
和Read.xaml:
<Grid>
<TextBlock Foreground="White"
FontSize="20"
Text="{Binding Name}" />
<Label Content="Read view"/>
</Grid>
最后,我在视图/客户中有一个空的CustomerView用户控件,在视图/客户中有一个CustomerWorkspace视图:
<Grid>
<ListBox x:Name="Items"
Margin="5"
SelectedItem="{Binding SelectedItem}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Margin="5" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ContentControl cal:View.Context="{Binding State, Mode=TwoWay}" cal:View.Model="{Binding SelectedItem}"/>
</Grid>
最后,我在根文件夹中使用AppBootstrapper创建了DocumentWorkspace:
public class AppBootstrapper : BootstrapperBase
{
public AppBootstrapper()
: base()
{
Initialize();
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
base.DisplayRootViewFor<CustomerWorkspaceViewModel>();
}
}
public abstract class DocumentWorkspace<TDocument> : Conductor<TDocument>.Collection.OneActive
where TDocument : class, INotifyPropertyChanged, IDeactivate, IHaveDisplayName
{
public enum DocumentWorkspaceState
{
Read,
Edit
}
DocumentWorkspaceState state = DocumentWorkspaceState.Read;
public DocumentWorkspaceState State
{
get { return state; }
set
{
if (state == value)
return;
state = value;
NotifyOfPropertyChange(() => State);
}
}
}
我希望和期望的是,在列表框中选择一个由DocumentWorkspace对象组成的项目时,从一个视图编辑切换到另一个视图读取。select正在工作,SelectedItem setter正在被激发,DocumentWorkspace中的状态设置正确。但是Caliburn.Micro似乎找不到SelectedItem生成的CustomServiceWModel的视图。我真的试图在这篇文章中只包含重现问题所需的内容
请注意,我试图做的事情的文档遵循at的要求,因此mvermef为我指明了正确的方向。我需要修复我的名称空间。我还需要创建一个名为“视图下的客户”的文件夹,并将“编辑”和“读取”视图移动到其中。然后我需要再次修复我的名称空间。顺便说一句,Resharper是一个很好的工具 那么,除了名称空间之外,还有什么问题?在CustomerWorkSpace视图中,我 这导致Caliburn.Micro在基类DocumentWorkspace中的CustomerWorkspaceViewModel中查找状态属性,在本例中读取结果。这里只需要一根绳子。有一个读取视图,但它位于名为CustomerWorkspace的文件夹中。它需要位于名为Customer的文件夹中,因为SelectedItem属性的类型为CustomerServiceWModel 结果我甚至不需要空的CustomerView。只要Caliburn.Micro可以找到与ViewModel类型减去ViewModel同名的文件夹,并且名称空间与文件夹结构匹配,它就应该可以找到您的视图 以下是我的完整文件夹结构:
Caliburn micro在查找视图和视图模型时使用约定。在这种情况下,您需要一个视图模型/客户来保存视图模型。视图将位于视图/客户中。它将根据默认命名约定在views文件夹中查找Customer或CustomerView。您好@Nkosi,所有与我的客户相关的viewmodels都在viewmodels/Customers中,而我的视图都在views/Customers中。如果您查看文档,我有一个名为Views/Customers/CustomerWorkspace的文件夹,用于保存我的读取和编辑视图。确保所有内容都是jives,否则您将只得到conventionmanager显示的namespace.viewmodel.somefolder.somestring,而不是视图。。太棒了,我在很多个月前就已经学会了如何使用我的应用程序的精确结构。这是在黑暗中拍摄的,没有看到你的文件夹结构。