2
將HubPage部分中定義的視圖綁定到相應的ViewModels需要什麼流程?使用CaliburnMicro在HubPage中綁定ViewModel
<Hub Header="{Binding HubHeader}" >
<HubSection x:Name="NewestOffers" Header="{Binding NewestOffersHeader}" IsHeaderInteractive="True" >
<DataTemplate >
<local:NewestOffersView DataContext="{Binding NewestOffers}"/>
</DataTemplate>
</HubSection>
<HubSection Header="{Binding SearchHeader}" IsHeaderInteractive="True" >
<DataTemplate x:Name="SearchView">
<local:SearchView/>
</DataTemplate>
</HubSection>
<HubSection Header="{Binding AddOfferHeader}" IsHeaderInteractive="True" >
<DataTemplate>
<local:AddOfferView/>
</DataTemplate>
</HubSection>
<HubSection Header="{Binding AccountHeader}" IsHeaderInteractive="True">
<DataTemplate>
<local:AccountView/>
</DataTemplate>
</HubSection>
</Hub>
我都創造了的ViewModels,如NewestOffersViewModel,SearchViewModel等,但它沒有得到約束。我不忘記在容器配置中註冊它們。
@Edit: 用於容納所述輪轂的頁面視圖模型:
public class MainPageViewModel : PropertyChangedBase
{
public string HubHeader
{
get { return "Second Hand Bookshop"; }
}
public SearchViewModel SearchView { get; set; }
public NewestOffersViewModel NewestOffersViewModel { get; set; }
public MainPageViewModel()
{
SearchView = new SearchViewModel();
NewestOffersViewModel = new NewestOffersViewModel();
}
public string SearchSectionHeader
{
get { return "Search"; }
}
而片MainPageView的(我試圖兵NewestOffersView到NewestOffersViewModel)。
<Hub Header="{Binding HubHeader}" >
<HubSection Header="{Binding NewestOffersHeader}" IsHeaderInteractive="True" >
<DataTemplate >
<ContentControl x:Name="NewestOffersViewModel" />
</DataTemplate>
</HubSection>