WPF Caliburn.Micro DisplayName不绑定到Tab控件的Tab Item标头

时间:2019-10-10 12:25:30

标签: wpf caliburn.micro

我有一个标签控件:

<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 { }

0 个答案:

没有答案
相关问题