2016-11-04 26 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)