【发布时间】:2016-03-19 22:54:47
【问题描述】:
我有一个包含LeftView 的ShellView,它本身包含一个LeftTopView。我遇到的问题是 LeftTopView 没有显示来自 LeftTopViewModel 的信息。
当我将 boostrapper 更改为使用 DisplayRootViewFor<LeftViewModel>(); 而不是 DisplayRootViewFor<ShellViewModel>(); 时,我会看到组合框充满了值。
当然,我在这里遗漏了一些关于为什么在显示 ShellView 时组合框不显示数据的内容。 Caliburn.Micro 是否只绑定层次结构中的单个级别?
代码如下:
public class ShellViewModel : Screen
{
public LeftViewModel Left { get; set; }
public ShellViewModel()
{
this.DisplayName = "The title of the application";
Left = new LeftViewModel() { LeftTop = new LeftTopViewModel() };
}
}
public class LeftViewModel : PropertyChangedBase
{
public string LeftTitle { get; set; }
public LeftTopViewModel LeftTop { get; set; }
public LeftViewModel()
{
LeftTitle = "this is visible";
LeftTop = new LeftTopViewModel();
}
}
public class LeftTopViewModel : PropertyChangedBase
{
public string Title { get; set; }
public List<string> Names { get; set; }
public string SelectedName { get; set; }
public LeftTopViewModel()
{
Title = "Left-top title";
Names = new List<string>() { "Dan", "Mark" };
SelectedName = "Dan";
}
}
上述视图模型的 xaml 文件是这样定义的。
ShellView.xaml(窗口)
<Grid>
<views:LeftView cal:Bind.Model="{Binding Left}" />
</Grid>
LeftView.xaml(用户控件)
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Label x:Name="LeftTitle" Grid.Row="0" />
<views:LeftTopView cal:Bind.Model="{Binding LeftTop}" Grid.Row="1"/>
</Grid>
LeftTopView.xaml (用户控件)
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="Title" Grid.Row="0" />
<ComboBox x:Name="Names" Grid.Row="1" />
</Grid>
【问题讨论】:
标签: c# wpf caliburn.micro