我正在尝试使用Caliburn.Micro和WPF学习。如何在一个视图中添加多个视图?
<Window x:Class="ProjectName.Views.MainView"
...>
<Grid>
<views:MyControlView />
</Grid>
</Window>
另一个视图,搭配视图模型:MyControlViewModel
<UserControl x:Class="ProjectName.Views.MyControlView"
...>
<Grid>
...
</Grid>
</UserControl>
如果我只是添加视图,它不会检测到具有相应名称的视图模型。我该如何将其绑定到视图模型?我尝试了不同的引导程序并使用类似于cal:Bind.Model="path/classname/merge of the two"的东西。尝试将其添加到mainview和usercontrol(MyControlView)中。非常感谢任何关于此问题的帮助。我卡住了,我真的很想使用Caliburn.Micro :)
最好的问候, diamondfish
编辑:我仍然无法使其工作,问题似乎在引导程序或其他地方。但是为了澄清,在这里是我运行测试项目的代码。
MainView xaml:
<Window x:Class="Test.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
xmlns:views="clr-namespace:Test.Views"
Title="MainWindow" Height="360" Width="640">
<Grid>
<views:MyControlView />
</Grid>
主ViewModel代码:
public partial class MainViewModel : PropertyChangedBase
{
}
我ControlView的XAML代码:
<UserControl x:Class="Test.Views.MyControlView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
cal:Bind.Model="Test.MyControlViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Text="{Binding MyProp}"/>
</Grid>
我的 ControlView 代码:
public class MyControlViewModel : PropertyChangedBase
{
public string MyProp
{
get { return "Working"; }
}
}
错误截图:http://clip2net.com/s/1gtgt
我已经尝试过
cal:Bind.Model="Test.ViewModels.MyControlViewModel"
还尝试了 cal-reference 但也没有用:
xmlns:cal="http://www.caliburnproject.org"
我项目的截图:http://clip2net.com/s/1gthM
由于文档大多是针对silverlight,有时是针对Caliburn而不是CM,所以我可能实现了错误的引导程序。 对于这个测试项目,它只是这样的:(在App.xaml中更改.xaml)
public class BootStrapper : Bootstrapper<MainViewModel>
{
}
请在这里帮助我!似乎我错过了一些基础知识 :)