我正在尝试使用带有WPF的Caliburn.Micro学习.如何在视图中添加多个视图?
<Window x:Class="ProjectName.Views.MainView"
...>
<Grid>
<views:MyControlView />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
另一个视图,使用viewmodel:MyControlViewModel
<UserControl x:Class="ProjectName.Views.MyControlView"
...>
<Grid>
...
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
如果我只是添加视图,它将不会检测到它具有具有适当名称的viewmodel.我怎么能把它绑在上面呢?
我已尝试使用不同的bootstrappers并使用类似cal:Bind.Model ="path/classname/merge of the two".试图将其添加到主视图和usercontrol(MyControlView).我非常感谢有关此事的任何帮助.我几乎卡住了,我真的想用Caliburn.Micro :)
最好的问候,钻石鱼
编辑:我仍然无法让它工作,问题似乎是在引导程序或其他东西.但只是为了澄清,这是我的代码,我正在运行testproject.
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>
Run Code Online (Sandbox Code Playgroud)
MainViewModel代码:
public partial class MainViewModel : PropertyChangedBase
{
}
Run Code Online (Sandbox Code Playgroud)
MyControlView 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>
Run Code Online (Sandbox Code Playgroud)
MyControlView代码:
public class MyControlViewModel : PropertyChangedBase
{
public string MyProp
{
get …Run Code Online (Sandbox Code Playgroud)