我正在嘗試使用WPF使用Caliburn.Micro。我如何在視圖中添加多個視圖?使用WPF和Caliburn.Micro在視圖中添加多個視圖
<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>
MainViewModel代碼:
public partial class MainViewModel : PropertyChangedBase
{
}
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>
MyControlView代碼:錯誤的
public class MyControlViewModel : PropertyChangedBase
{
public string MyProp
{
get { return "Working"; }
}
}
截圖:http://clip2net.com/s/1gtgt
我已經試過
cal:Bind.Model="Test.ViewModels.MyControlViewModel"
爲好。也嘗試了CAL-參考:
xmlns:cal="http://www.caliburnproject.org"
我的項目http://clip2net.com/s/1gthM
由於文檔的屏幕截圖大多是Silverlight的,有時是卡利而不是CM,我可能已經實現了引導程序錯誤。對於這個測試項目,就像這樣:(使用App.xaml中的.xaml-change)
public class BootStrapper : Bootstrapper<MainViewModel>
{
}
請幫我看看這裏!現在看來似乎是我失蹤:)一些基本的東西
- 編輯帖子包含MVVM標籤,歡迎來到SO! – EtherDragon
檢查anser - 我添加了一個關於導出類型的部分。這是c.m找到與視圖相關的ViewModel的重要條件。 – EtherDragon