我有一个标签控件:
<TabControl Grid.Row="1" x:Name="Items"/>
DataContext是Caliburn.Micro.Conductor<CompanyScreen>.Collection.OneActive
,在构造函数的Items
集合中添加了几项。
TabItems会按预期生成,但是其标头内容是ToString()
的结果,而不是将它们添加到DisplayName
集合之前设置的Items
的结果。 / p>
示例:
<UserControl x:Class="Company.ParentView"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ContentControl x:Name="MyViewModel"/>
</UserControl>
<UserControl x:Class="Company.MyView"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TabControl x:Name="Items"/>
</UserControl>
public class ParentViewModel : Screen
{
public class ParentViewModel()
{
MyViewModel = new MyViewModel(new FooViewModel(), new BarViewModel());
}
MyViewModel _myViewModel;
public MyViewModel MyViewModel
{
get => _myViewModel;
set
{
_myViewModel = value;
NotifyOfPropertyChange(nameof(MyViewModel));
}
}
}
public class MyViewModel : Caliburn.Micro.Conductor<Screen>.Collection.OneActive
{
public MyViewModel(FooViewModel foo, BarViewModel bar)
{
foo.DisplayName = "Foo Tab";
bar.DisplayName = "Bar Tab";
Items.Add(foo);
Items.Add(bar);
}
}
public class FooViewModel : Screen { }
public class BarViewModel : Screen { }