如何在Caliburn Micro中为嵌套视图模型提供设计时支持?

时间:2015-04-22 10:57:01

标签: wpf visual-studio-2013 user-controls caliburn.micro design-time-data

使用VS2013和Caliburn.Micro 2.0.2

鉴于这个例子:

  1. 具有嵌套视图模型属性和
  2. 的shell视图模型
  3. shell和嵌套视图模型都具有class MyTestCase(TestCase): def setUp(): # Flush any cached values request.bind({}) 属性:
  4. Project

    似乎在设计时,嵌套视图模型属性被忽略。有没有办法支持这个?

    Name

    public class NestedViewModel : PropertyChangedBase
    {
        private string _name;
    
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                NotifyOfPropertyChange(() => Name);
            }
        }
    
        public NestedViewModel()
        {
            Name = "Nested";
        }
    }
    

    绿色标签显示设计器中嵌套视图模型的正确<UserControl x:Class="WpfApplication1.Views.NestedView" 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="http://www.caliburnproject.org" xmlns:viewModels="clr-namespace:WpfApplication1.ViewModels" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewModels:NestedViewModel, IsDesignTimeCreatable=True}" cal:Bind.AtDesignTime="True"> <Grid> <Label x:Name="Name" FontSize="16" Background="LightGreen"/> </Grid> </UserControl>

    Nested

    Name

    public class ShellViewModel : PropertyChangedBase
    {
        private string _name;
        private NestedViewModel _nestedViewModel;
    
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                NotifyOfPropertyChange(() => Name);
            }
        }
    
        public NestedViewModel NestedViewModel
        {
            get { return _nestedViewModel; }
            set
            {
                if (Equals(value, _nestedViewModel)) return;
                _nestedViewModel = value;
                NotifyOfPropertyChange(() => NestedViewModel);
            }
        }
    
        public ShellViewModel()
        {
            NestedViewModel = new NestedViewModel();
            Name = "Shell";
        }
    }
    

    绿色标签应该在设计器中显示嵌套视图模型<UserControl x:Class="WpfApplication1.Views.ShellView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:WpfApplication1.ViewModels" xmlns:cal="http://www.caliburnproject.org" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewModels:ShellViewModel, IsDesignTimeCreatable=True}" cal:Bind.AtDesignTime="True"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <ContentControl Grid.Row="0" x:Name="NestedViewModel"/> <Label Grid.Row="1" x:Name="Name" FontSize="16" Background="RoyalBlue"/> </Grid> </UserControl> 属性,而是显示shell视图模型的值:

    Shell

    它在运行时正确绑定:

    Run time

    Example

0 个答案:

没有答案