2016-11-04 72 views
0

我试图在已经应用了一些设置的ContainerPart的迁移中创建新的内容类型。ContainerPart在新类型上的设置

ContentDefinitionManager.AlterTypeDefinition("NewType", 
    cfg => cfg 
     .DisplayedAs("New Type") 
     .WithPart(typeof(TitlePart).Name) 
     .WithPart(typeof(ContainerPart).Name) 
      .WithSetting("ContainerPartSettings.ItemsShownDefault", "False") 
     .WithPart(typeof(CommonPart).Name) 
     .WithPart(typeof(IdentityPart).Name) 
     .Creatable() 
     .Listable() 
    ); 

ItemsShown默认情况下,迁移后,保持其默认值为True。

我试过的这几个不同的版本:

  • 重命名 “ContainerPartSettings” 到其他版本一样ContainerSettings,ContainerTypePartSettings

  • 不使用的typeof()函数并指定与零件直接字符串

从我所知道的,ContainerSettings使用不同的方法来存储它的值比较给其他人如AutorouteSettings。在你的代码

回答

2

来看,你是在你的类型链接中的设置,而不是部分的:

.WithPart(typeof(ContainerPart).Name) // close the WithPart function 

    // which means the following line is chained to the type 
    .WithSetting("ContainerPartSettings.ItemsShownDefault", "False") 

为了解决这个问题,像这样做:

.WithPart(typeof(ContainerPart).Name, part => part 

    // inside the ContainerPart context 
    .WithSetting("ContainerPartSettings.ItemsShownDefault", "False") 
) // Close ContainerPart context 

.WithPart(..) 

如果您的确想要设置类型而不是零件的设置,请使用ContainerTypePartSettings defi类ned here

.WithPart(typeof(ContainerPart).Name) 

// Set settings on the type instead of the part 
.WithSetting("ContainerTypePartSettings.ItemsShownDefault", false)