ApiExamples.ExLists.CreateAndUseListStyle C# (CSharp) Метод

CreateAndUseListStyle() приватный Метод

private CreateAndUseListStyle ( ) : void
Результат void
        public void CreateAndUseListStyle()
        {
            //ExStart
            //ExFor:StyleCollection.Add(StyleType,String)
            //ExFor:Style.List
            //ExFor:StyleType
            //ExFor:List.IsListStyleDefinition
            //ExFor:List.IsListStyleReference
            //ExFor:List.IsMultiLevel
            //ExFor:List.Style
            //ExFor:ListLevelCollection
            //ExFor:ListLevelCollection.Count
            //ExFor:ListLevelCollection.Item
            //ExFor:ListCollection.Add(Style)
            //ExSummary:Shows how to create a list style and use it in a document.
            Document doc = new Document();

            // Create a new list style. 
            // List formatting associated with this list style is default numbered.
            Style listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");

            // This list defines the formatting of the list style.
            // Note this list can not be used directly to apply formatting to paragraphs (see below).
            Aspose.Words.Lists.List list1 = listStyle.List;

            // Check some basic rules about the list that defines a list style.
            Console.WriteLine("IsListStyleDefinition: " + list1.IsListStyleDefinition);
            Console.WriteLine("IsListStyleReference: " + list1.IsListStyleReference);
            Console.WriteLine("IsMultiLevel: " + list1.IsMultiLevel);
            Console.WriteLine("List style has been set: " + (listStyle == list1.Style));

            // Modify formatting of the list style to our liking.
            for (int i = 0; i < list1.ListLevels.Count; i++)
            {
                ListLevel level = list1.ListLevels[i];
                level.Font.Name = "Verdana";
                level.Font.Color = Color.Blue;
                level.Font.Bold = true;
            }


            // Add some text to our document and use the list style.
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Using list style first time:");

            // This creates a list based on the list style.
            Aspose.Words.Lists.List list2 = doc.Lists.Add(listStyle);

            // Check some basic rules about the list that references a list style.
            Console.WriteLine("IsListStyleDefinition: " + list2.IsListStyleDefinition);
            Console.WriteLine("IsListStyleReference: " + list2.IsListStyleReference);
            Console.WriteLine("List Style has been set: " + (listStyle == list2.Style));

            // Apply the list that references the list style.
            builder.ListFormat.List = list2;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();


            builder.Writeln("Using list style second time:");

            // Create and apply another list based on the list style.
            Aspose.Words.Lists.List list3 = doc.Lists.Add(listStyle);
            builder.ListFormat.List = list3;
            builder.Writeln("Item 1");
            builder.Writeln("Item 2");
            builder.ListFormat.RemoveNumbers();

            builder.Document.Save(MyDir + @"\Artifacts\Lists.CreateAndUseListStyle.doc");
            //ExEnd

            // Verify properties of list 1
            Assert.IsTrue(list1.IsListStyleDefinition);
            Assert.IsFalse(list1.IsListStyleReference);
            Assert.IsTrue(list1.IsMultiLevel);
            Assert.AreEqual(listStyle, list1.Style);

            // Verify properties of list 2
            Assert.IsFalse(list2.IsListStyleDefinition);
            Assert.IsTrue(list2.IsListStyleReference);
            Assert.AreEqual(listStyle, list2.Style);
        }