public void initPasta() { generic = false; RecipeView ar = new RecipeView("Alfredo", "30 min", 5); RecipeView br = new RecipeView("Linguini", "35 min", 4); RecipeView cr = new RecipeView("Penne", "27 min", 3.5); RecipeView dr = new RecipeView("Mac and Cheese", "32 min", 3); ListItem al = new ListItem(ar); ListItem bl = new ListItem(myMain.spaghetti); ListItem cl = new ListItem(br); ListItem dl = new ListItem(cr); ListItem el = new ListItem(dr); myMain.itemOfLists[0] = al; myMain.itemOfLists[1] = bl; myMain.itemOfLists[2] = cl; myMain.itemOfLists[3] = dl; myMain.itemOfLists[4] = el; items.Children.Clear(); items.Children.Add(al); items.Children.Add(bl); items.Children.Add(cl); items.Children.Add(dl); items.Children.Add(el); }
/// <summary> /// 显示序号 /// </summary> private void ShwoNumber() { System.Windows.Documents.List listx = new System.Windows.Documents.List(); listx.Margin = new Thickness() { Left = 3 }; // Set the space between the markers and list content to 25 DIP. listx.MarkerOffset = 5; // Use uppercase Roman numerals. listx.MarkerStyle = TextMarkerStyle.Decimal; // Start list numbering at 5. listx.StartIndex = 1; // Create the list items that will go into the list. System.Windows.Documents.ListItem liV = new System.Windows.Documents.ListItem(new System.Windows.Documents.Paragraph(new System.Windows.Documents.Run(""))); // Finally, add the list items to the list. listx.ListItems.Add(liV); if (RichTextBox1.Document.Blocks.Count == 2) { RichTextBox1.Document.Blocks.Remove(RichTextBox1.Document.Blocks.LastBlock); } RichTextBox1.Document.Blocks.Add(listx); RichTextBox1.Focus(); RichTextBox1.CaretPosition = this.RichTextBox1.Document.ContentEnd; }
private void SetListItems() { foreach (XElement clientElement in this.m_ShipmentElement.Element("ClientOrderCollection").Elements("ClientOrder")) { Run nameblock = new Run("Patient: " + clientElement.Element("PatientName").Value + " Birthdate: " + clientElement.Element("PBirthdate").Value); nameblock.FontSize = 12; Paragraph clientParagraph = new Paragraph(nameblock); clientParagraph.Padding = new Thickness(50, 10, 0, 10); ListItem listitem = new ListItem(clientParagraph); this.DetailsList.ListItems.Add(listitem); foreach (XElement specimenElement in clientElement.Element("ClientOrderDetailCollection").Elements("ClientOrderDetail")) { Run lineOne = new Run(specimenElement.Element("ContainerId").Value + " Collected: " + specimenElement.Element("CollectionDate").Value); lineOne.FontSize = 12; Paragraph paragraphOne = new Paragraph(lineOne); paragraphOne.Padding = new Thickness(55, 10, 0, 10); ListItem listOne = new ListItem(paragraphOne); this.DetailsList.ListItems.Add(listOne); Run lineTwo = new Run(specimenElement.Element("Description").Value + " By: " + specimenElement.Element("OrderedBy").Value); lineTwo.FontSize = 12; Paragraph paragraphTwo = new Paragraph(lineTwo); paragraphTwo.Padding = new Thickness(55, 10, 0, 10); ListItem listTwo = new ListItem(paragraphTwo); this.DetailsList.ListItems.Add(listTwo); } } }
public Block CreateDataList() { var list = new List {MarkerStyle = TextMarkerStyle.None}; foreach (var sug in this._groups.OrderByDescending(x=>x.Count)) { var p = new Paragraph(); p.Inlines.Add(new Run(new string('▄', sug.Count))); p.Inlines.Add(new LineBreak()); p.Inlines.Add(new Run(sug.SuggestionItems.First().Text) { FontWeight = FontWeights.Bold }); p.Inlines.Add(new LineBreak()); if (sug.SuggestionItems.Count > 1) { p.Inlines.Add(new Run("Synonyme: ")); p.Inlines.Add(new Run(sug.SuggestionItems.Skip(1).First().Text) { FontStyle = FontStyles.Italic }); foreach (var syn in sug.SuggestionItems.Skip(2)) { p.Inlines.Add(new Run(", ")); p.Inlines.Add(new Run(syn.Text) { FontStyle = FontStyles.Italic }); } p.Inlines.Add(new LineBreak()); } p.Inlines.Add(new Run("Anzahl: ")); p.Inlines.Add(new Run(sug.Count.ToString()) { FontWeight = FontWeights.Bold }); p.Inlines.Add(new LineBreak()); var li = new ListItem(); li.Blocks.Add(p); list.ListItems.Add(li); } return list; }
public void addItem(ListItem it) { forecastItem obj = new forecastItem(); obj.Margin = new Thickness(0, 5, 0, 0); obj.init(it); PanelMain.Children.Add(obj); }
/// <summary> /// Initializes a new instance of a List class specifying its first ListItem child. /// </summary> /// <param name="listItem"> /// ListItem to be inserted as a first child of this List. /// </param> public List(ListItem listItem) : base() { if (listItem == null) { throw new ArgumentNullException("listItem"); } this.ListItems.Add(listItem); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.Introduction = ((System.Windows.Documents.ListItem)(target)); return; } this._contentLoaded = true; }
internal static OrgStructureEntityModel GetInstance(ListItem item) { OrgStructureEntityModel newOrg = new OrgStructureEntityModel(); newOrg.ID = item.Id; newOrg.IsActive = (bool)GetPropertyValue(item.FieldValues[Columns.Inactive], Columns.Inactive); newOrg.LevelName = (OrgStructureEntityModel.LevelNames)GetPropertyValue(item.FieldValues[Columns.Level], Columns.Level); newOrg.OrderNo = Int32.Parse(GetPropertyValue(item.FieldValues[Columns.OrderNo], Columns.OrderNo).ToString()); newOrg.ParentID = Int32.Parse(GetPropertyValue(item.FieldValues[Columns.ParentID], Columns.ParentID).ToString()); newOrg.Title = GetPropertyValue(item.FieldValues[Columns.Title], Columns.Title).ToString(); newOrg.OriginalTitle = newOrg.Title; return newOrg; }
void defaultView() { Sp1.Children.Clear(); ListItem al = new ListItem(ar); ListItem bl = new ListItem(br); ListItem cl = new ListItem(cr); ListItem dl = new ListItem(dr); ListItem e1 = new ListItem(myMain.orangeAvoChicken); Sp1.Children.Add(al); Sp1.Children.Add(bl); Sp1.Children.Add(e1); Sp1.Children.Add(cl); Sp1.Children.Add(dl); }
void defaultView() { Sp1.Children.Clear(); ListItem al = new ListItem(ar); ListItem bl = new ListItem(br); ListItem cl = new ListItem(cr); ListItem dl = new ListItem(dr); ListItem e1 = new ListItem(myMain.spaghetti); Sp1.Children.Add(al); Sp1.Children.Add(e1); Sp1.Children.Add(bl); Sp1.Children.Add(cl); Sp1.Children.Add(dl); }
public void defaultView() { Sp1.Children.Clear(); ListItem al = new ListItem(ar); ListItem bl = new ListItem(br); ListItem cl = new ListItem(cr); ListItem dl = new ListItem(dr); ListItem e1 = new ListItem(myMain.hawiianSmoothie); Sp1.Children.Add(al); Sp1.Children.Add(bl); Sp1.Children.Add(e1); Sp1.Children.Add(cl); Sp1.Children.Add(dl); }
void defaultView() { // Sp1.Children.Clear(); // ListItem item1 = new ListItem(myMain.aSundae.getName(),myMain.aSundae.getTime(),myMain.aSundae); // Sp1.Children.Add(item1); Sp1.Children.Clear(); ListItem al = new ListItem(ar); ListItem bl = new ListItem(br); ListItem cl = new ListItem(cr); ListItem dl = new ListItem(dr); ListItem e1 = new ListItem(myMain.aSundae); Sp1.Children.Add(al); Sp1.Children.Add(e1); Sp1.Children.Add(bl); Sp1.Children.Add(cl); Sp1.Children.Add(dl); }
public void initChicken() { generic = false; RecipeView ar = new RecipeView("Chicken and Rice", "25 min", 2.5); RecipeView br = new RecipeView("Chicken Burgers", "40 min", 4); RecipeView cr = new RecipeView("Club Sandwiche", "25 min", 4); RecipeView dr = new RecipeView("Chicken Curry", "37 min", 4.5); ListItem al = new ListItem(dr); ListItem bl = new ListItem(myMain.orangeAvoChicken); ListItem cl = new ListItem(br); ListItem dl = new ListItem(cr); ListItem el = new ListItem(ar); myMain.itemOfLists[0] = al; myMain.itemOfLists[1] = bl; myMain.itemOfLists[2] = cl; myMain.itemOfLists[3] = dl; myMain.itemOfLists[4] = el; items.Children.Clear(); items.Children.Add(al); items.Children.Add(bl); items.Children.Add(cl); items.Children.Add(dl); items.Children.Add(el); }
//-------------------------------------------------------------------- // // Internal Methods // //-------------------------------------------------------------------- #region Internal Methods /// <summary> /// Returns the integer "index" of a specified ListItem that is an immediate child of /// this List. This index is defined to be a sequential counter of ListElementItems only /// (skipping other elements) among this List's immediate children. /// /// The list item index of the first child of type ListItem is specified by /// this.StartListIndex, which has a default value of 1. /// /// The index returned by this method is used in the formation of some ListItem /// markers such as "(b)" and "viii." (as opposed to others, like disks and wedges, /// which are not sequential-position-dependent). /// </summary> /// <param name="item">The item whose index is to be returned.</param> /// <returns>Returns the index of a specified ListItem.</returns> internal int GetListItemIndex(ListItem item) { // Check for valid arg if (item == null) { throw new ArgumentNullException("item"); } if (item.Parent != this) { throw new InvalidOperationException(SR.Get(SRID.ListElementItemNotAChildOfList)); } // Count ListItem siblings (not other element types) back to first item. int itemIndex = StartIndex; TextPointer textNav = new TextPointer(this.ContentStart); while (textNav.CompareTo(this.ContentEnd) != 0) { // ListItem is a content element, so look for ElementStart runs only if (textNav.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart) { DependencyObject element = textNav.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward); if (element is ListItem) { if (element == item) { break; } if (itemIndex < int.MaxValue) { ++itemIndex; } } // Skip entire content element content, because we are looking // only for immediate children. textNav.MoveToPosition(((TextElement)element).ElementEnd); } else { textNav.MoveToNextContextPosition(LogicalDirection.Forward); } } return itemIndex; }
private void AddList(FlowDocument odtFile, XmlNode tableNode) { System.Windows.Documents.List list = new System.Windows.Documents.List(); foreach (XmlNode listitem in tableNode.ChildNodes) { if (listitem.Name == "text:list-item") { System.Windows.Documents.Paragraph par = new System.Windows.Documents.Paragraph(); par.Tag = "ListItem"; //Line Spacing par.Margin = new Thickness(2); par.FontSize = DEFAULT_FONTSIZE; par.Inlines.Add(new Run(listitem.InnerText)); System.Windows.Documents.ListItem item = new System.Windows.Documents.ListItem(par); list.ListItems.Add(item); } } odtFile.Blocks.Add(list); }
private static void DecreaseIndentation(TextSelection thisSelection, ListItem parentListItem, ListItem immediateListItem) { if (immediateListItem != null) { TextRangeEditLists.UnindentListItems(thisSelection); } else if (parentListItem != null) { TextRangeEditLists.ConvertParagraphsToListItems(thisSelection, TextMarkerStyle.Disc); TextRangeEditLists.UnindentListItems(thisSelection); } else { if (thisSelection.IsEmpty) { // When selection is empty, handle indentation based on current TextIndent property of the paragraph. Block paragraphOrBlockUIContainer = thisSelection.Start.ParagraphOrBlockUIContainer; if (paragraphOrBlockUIContainer is BlockUIContainer) { // Decrement BlockUIContainer's leading margin. TextRangeEdit.IncrementParagraphLeadingMargin(thisSelection, /*increment:*/20, PropertyValueAction.DecreaseByAbsoluteValue); } else { // Create implicit paragraph if at a potential paragraph position, such as empty FlowDocument, TableCell. CreateImplicitParagraphIfNeededAndUpdateSelection(thisSelection); Paragraph paragraph = thisSelection.Start.Paragraph; Invariant.Assert(paragraph != null, "EnsureInsertionPosition must guarantee a position in text content"); // When selection is empty, handle indentation based on current TextIndent property of the paragraph. if (paragraph.TextIndent > 20) { // Reset text indent to 20. TextRangeEdit.SetParagraphProperty(thisSelection.Start, thisSelection.End, Paragraph.TextIndentProperty, 20.0, PropertyValueAction.SetValue); } else if (paragraph.TextIndent > 0) { // Reset text indent to 0. TextRangeEdit.SetParagraphProperty(thisSelection.Start, thisSelection.End, Paragraph.TextIndentProperty, 0.0, PropertyValueAction.SetValue); } else { // Decrement paragraph leading margin. TextRangeEdit.IncrementParagraphLeadingMargin(thisSelection, /*increment:*/20, PropertyValueAction.DecreaseByAbsoluteValue); } } } else { // For non-empty selection, always decrement paragraph margin. TextRangeEdit.IncrementParagraphLeadingMargin(thisSelection, /*increment:*/20, PropertyValueAction.DecreaseByAbsoluteValue); } } }
/// <summary> /// Loads the chooser from the initialList of strings passed in /// </summary> /// <param name="initialList"></param> public void LoadChooser(List<string> initialList) { baseItems = new ObservableCollection<string>(); foreach (var item in initialList) { ListItem li = new ListItem(); baseItems.Insert(0, item); } generateFilteredList(filter.Text.Trim()); this.list.ItemsSource = filteredItems; }
public object ToUIElement() { ListItem res = new ListItem(); TextBlock txt = new TextBlock(); txt.Text = Team.ToString(); res.FontWeight = FontWeights.Bold; res.Foreground = UIBrush; return res; }
private static void ToggleNumbering(TextSelection thisSelection, ListItem parentListItem, ListItem immediateListItem, List list) { if (immediateListItem != null && HasNumericMarker(list)) { if (list.Parent is ListItem) { TextRangeEditLists.UnindentListItems(thisSelection); TextRangeEditLists.ConvertListItemsToParagraphs(thisSelection); } else { TextRangeEditLists.UnindentListItems(thisSelection); } } else if (immediateListItem != null) { list.MarkerStyle = TextMarkerStyle.Decimal; } else if (parentListItem != null) { TextRangeEditLists.ConvertParagraphsToListItems(thisSelection, TextMarkerStyle.Decimal); TextRangeEditLists.IndentListItems(thisSelection); } else { TextRangeEditLists.ConvertParagraphsToListItems(thisSelection, TextMarkerStyle.Decimal); } }
// Helper for EnsureInsertionPosition. // Generates minimally necessary content to ensure at least one insertion position. private static TextPointer CreateInsertionPositionInIncompleteContent(TextPointer position) { // Go inside the scoped element to its possible lowest level while (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart) { position = position.GetNextContextPosition(LogicalDirection.Forward); } while (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementEnd) { position = position.GetNextContextPosition(LogicalDirection.Backward); } DependencyObject parent = position.Parent; if (parent != null) { if (parent is Table) { // Creating implicit TableRowGroup TableRowGroup tableRowGroup = new TableRowGroup(); tableRowGroup.Reposition(position, position); position = tableRowGroup.ContentStart; parent = position.Parent; } if (parent is TableRowGroup) { // Creating implicit TableRow TableRow tableRow = new TableRow(); tableRow.Reposition(position, position); position = tableRow.ContentStart; parent = position.Parent; } if (parent is TableRow) { // Creating implicit TableCell TableCell tableCell = new TableCell(); tableCell.Reposition(position, position); position = tableCell.ContentStart; parent = position.Parent; } if (parent is List) { // Creating implicit ListItem ListItem listItem = new ListItem(); listItem.Reposition(position, position); position = listItem.ContentStart; parent = position.Parent; } if (parent is LineBreak || parent is InlineUIContainer) { position = ((Inline)parent).ElementStart; parent = position.Parent; } } if (parent == null) { // throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotInsertContentInThisPosition)); } TextPointer insertionPosition; if (TextSchema.IsValidChild(/*position:*/position, /*childType:*/typeof(Inline))) { insertionPosition = CreateImplicitRun(position); } else { Invariant.Assert(TextSchema.IsValidChild(/*position:*/position, /*childType:*/typeof(Block)), "Expecting valid parent-child relationship"); insertionPosition = CreateImplicitParagraph(position); } return insertionPosition; }
/// <summary> /// This is used to recursively add auto-outline links /// </summary> /// <param name="parent">The parent element from which to extract sections</param> /// <param name="depth">The current depth of the outline</param> /// <param name="maxDepth">The maximum depth to recurse for section titles</param> /// <returns>A list element containing the outline or null if no valid sections where found</returns> private static List InsertAutoOutline(XElement parent, int depth, int maxDepth) { List list = new List(), subList; ListItem listItem; Paragraph p; XElement titleElement; XAttribute address; string title; foreach(var section in parent.Elements(ddue + "section")) { titleElement = section.Element(ddue + "title"); if(titleElement == null || titleElement.Value.Trim().Length == 0) continue; title = reCondenseWhitespace.Replace(titleElement.Value, " ").Trim(); address = section.Attribute("address"); listItem = new ListItem(); list.ListItems.Add(listItem); p = new Paragraph(); listItem.Blocks.Add(p); if(address == null) p.Inlines.Add(new Run(title)); else p.Inlines.Add(new Hyperlink(new Run(title)) { NavigateUri = new Uri("link://#" + address.Value.Trim()) }); if(depth < maxDepth) foreach(var subsection in section.Elements(ddue + "sections")) { subList = InsertAutoOutline(subsection, depth + 1, maxDepth); if(subList != null) listItem.Blocks.Add(subList); } } return (list.ListItems.Count != 0) ? list : null; }
private ListItem AddListItem(XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet) { // Parameter validation Hashtable localProperties = new Hashtable(); GetElementProperties(htmlElement, inheritedProperties, localProperties, stylesheet); ListItem li = new ListItem(); // Process children of the ListItem for (XmlNode htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling) { Block b = AddBlock(htmlChildNode, localProperties, stylesheet); if (b != null) li.Blocks.Add(b); } // Apply local properties to list to set marker attribute if specified ApplyLocalProperties(li, localProperties, /*isBlock:*/true); return li; }
private static int GetCharOffsetToPosition(ListItem listItem, TextPointer position, out TextPointer result) { return GetCharOffsetToPosition(listItem.Blocks, position, out result); }
public void Deserialize(XmlNode xmlNode, FlowDocument flowDocument) { var list = new List{ MarkerStyle = _markerStyle }; foreach (XmlNode listItemNode in xmlNode.ChildNodes) { var listItem = new ListItem(); foreach (XmlNode listItemBlockNode in listItemNode.ChildNodes) { var paragraph = new Paragraph(); foreach (XmlNode listItemInlineNode in listItemBlockNode.ChildNodes) { var run = new Run(); foreach (XmlAttribute attribute in listItemInlineNode.Attributes) { if (attribute.Name != "StyleName") run.GetType().GetProperty(attribute.Name).SetValue(run, ParagraphSerializationHelper.PropertyConverters[attribute.Name].ConvertFromString( attribute.InnerText)); } if(xmlNode.Attributes["StyleName"] != null) FlowDocumentHelper.SetStyleName(run, xmlNode.Attributes["StyleName"].InnerText); paragraph.Inlines.Add(run); } listItem.Blocks.Add(paragraph); } list.ListItems.Add(listItem); } flowDocument.Blocks.Add(list); }
private static TextPointer GetPointerFromCharOffset(ListItem listItem, ref int charOffset) { return GetPointerFromCharOffset(listItem.ElementEnd, listItem.Blocks, ref charOffset); }
public List(ListItem listItem) { Contract.Ensures(0 <= this.ListItems.Count); }
/// <summary> /// Renders DOM text elements recursively, i.e. including their childs. /// </summary> /// <param name="e">The root DOM text element.</param> /// <returns>The corresponding Wpf element.</returns> /// <exception cref="System.InvalidOperationException"> /// </exception> /// <exception cref="System.NotImplementedException"></exception> public object RenderRecursively(TextElement e) { object wpf = null; switch (e) { case BlockUIContainer buc: { wpf = new swd.BlockUIContainer(); } break; case FlowDocument flowDocument: { // make sure the standard colors were set flowDocument.Foreground = ExCSS.Color.Black; flowDocument.Background = ExCSS.Color.White; var flowDocumente = new swd.FlowDocument() { Name = NameOfFlowDocument }; if (TemplateBindingViewportWidth is null) { TemplateBindingViewportWidth = new Binding("ColumnWidth") { Source = flowDocumente } } ; if (TemplateBindingViewportHeight is null) { TemplateBindingViewportHeight = new Binding("ColumnWidth") { Source = flowDocumente } } ; // Binding to ColumnWidth is not optimal, but better than nothing! if (flowDocument.Background.HasValue) { flowDocumente.Background = GetBrushFromColor(flowDocument.Background.Value); } if (flowDocument.Foreground.HasValue) { flowDocumente.Foreground = GetBrushFromColor(flowDocument.Foreground.Value); } wpf = flowDocumente; } break; case Hyperlink hl: { var hle = new swd.Hyperlink(); if (!string.IsNullOrEmpty(hl.NavigateUri)) { if (System.Uri.TryCreate(hl.NavigateUri, UriKind.RelativeOrAbsolute, out var uri)) { hle.NavigateUri = uri; } } if (!string.IsNullOrEmpty(hl.TargetName)) { hle.TargetName = hl.TargetName; } wpf = hle; } break; case Image image: { var imagee = new System.Windows.Controls.Image(); if (!string.IsNullOrEmpty(image.Source)) { imagee.SetBinding(System.Windows.Controls.Image.SourceProperty, $"ImageProvider[{image.Source}]"); } if (image.Width == null && image.Height == null) { imagee.Stretch = System.Windows.Media.Stretch.Uniform; var binding = new Binding() { RelativeSource = RelativeSource.Self, Path = new System.Windows.PropertyPath("Source") }; binding.Converter = ImageToImageWidthConverter.Instance; imagee.SetBinding(System.Windows.Controls.Image.WidthProperty, binding); } else { imagee.Stretch = System.Windows.Media.Stretch.Uniform; } if (image.Width != null) { if (image.Width.IsPurelyAbsolute(out var widthPx)) { imagee.Width = widthPx; } else { var multibinding = new MultiBinding(); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportHeight.Source, Path = TemplateBindingViewportHeight.Path }); multibinding.Converter = CompoundLengthConverter.Instance; multibinding.ConverterParameter = GetCompoundLengthConverterParameters(image.Width); imagee.SetBinding(System.Windows.Controls.Image.WidthProperty, multibinding); } } if (image.Height != null) { if (image.Height.IsPurelyAbsolute(out var heightPx)) { imagee.Height = heightPx; } else { var multibinding = new MultiBinding(); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportHeight.Source, Path = TemplateBindingViewportHeight.Path }); multibinding.Converter = CompoundLengthConverter.Instance; multibinding.ConverterParameter = GetCompoundLengthConverterParameters(image.Height); imagee.SetBinding(System.Windows.Controls.Image.HeightProperty, multibinding); } } // set max-width and max-height if (image.MaxWidth != null && image.MaxWidth.Value.IsAbsolute) { imagee.MaxWidth = image.MaxWidth.Value.ToPixel(); } else if (image.MaxWidth == null || image.MaxWidth.Value.Type == ExCSS.Length.Unit.Vw) { double vwValue = image.MaxWidth.HasValue ? image.MaxWidth.Value.Value : 100; var binding = new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }; binding.Converter = RelativeSizeConverter.Instance; binding.ConverterParameter = vwValue; imagee.SetBinding(System.Windows.Controls.Image.MaxWidthProperty, binding); } else { throw new InvalidProgramException(); } if (image.MaxHeight != null && image.MaxHeight.Value.IsAbsolute) { imagee.MaxHeight = image.MaxHeight.Value.ToPixel(); } else if (image.MaxHeight == null || image.MaxHeight.Value.Type == ExCSS.Length.Unit.Vh) { double vhValue = image.MaxHeight.HasValue ? image.MaxHeight.Value.Value : 100; var binding = new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }; binding.Converter = RelativeSizeConverter.Instance; binding.ConverterParameter = vhValue; imagee.SetBinding(System.Windows.Controls.Image.MaxHeightProperty, binding); } else { throw new InvalidProgramException(); } wpf = imagee; } break; case InlineUIContainer iuc: { var inlineuiContainere = new swd.InlineUIContainer(); wpf = inlineuiContainere; } break; case LineBreak lb: { wpf = new swd.LineBreak(); } break; case List list: { var liste = new swd.List(); if (list.MarkerStyle.HasValue) { liste.MarkerStyle = ToMarkerStyle(list.MarkerStyle.Value); } wpf = liste; } break; case ListItem li: { wpf = new swd.ListItem(); } break; case Paragraph p: { var pe = new swd.Paragraph(); if (p.TextDecorations.HasValue) { pe.TextDecorations = ToTextDecorations(p.TextDecorations.Value); } if (p.TextIndent.HasValue) { pe.TextIndent = p.TextIndent.Value.IsAbsolute ? p.TextIndent.Value.ToPixel() : 0; } wpf = pe; } break; case Run run: { if (SplitIntoWords) { wpf = CreateTextElement_SeparateWords(run.Text); } else if (SplitIntoSentences) { wpf = CreateTextElement_SeparateSentences(run.Text); } else { wpf = new swd.Run(run.Text); } } break; case Section s: { wpf = new swd.Section(); } break; case Span span: { wpf = new swd.Span(); } break; case Table tb: { var tbe = new swd.Table(); foreach (var c in tb.Columns) { if (c.Width.HasValue) { tbe.Columns.Add(new swd.TableColumn() { Width = new System.Windows.GridLength(c.Width.Value) }); } else { tbe.Columns.Add(new swd.TableColumn()); } } wpf = tbe; } break; case TableCell tc: { var tce = new swd.TableCell(); if (1 != tc.ColumnSpan) { tce.ColumnSpan = tc.ColumnSpan; } if (1 != tc.RowSpan) { tce.RowSpan = tc.RowSpan; } if (tc.BorderBrush.HasValue) { tce.BorderBrush = new System.Windows.Media.SolidColorBrush(ToColor(tc.BorderBrush.Value)); } if (tc.BorderThickness.HasValue) { tce.BorderThickness = ToThickness(tc.BorderThickness.Value); } wpf = tce; } break; case TableRow trow: { wpf = new swd.TableRow(); } break; case TableRowGroup trg: { wpf = new swd.TableRowGroup(); } break; default: { wpf = null; } break; } // Render TextElement properties if (wpf is swd.TextElement te) { if (!string.IsNullOrEmpty(e.FontFamily)) { te.FontFamily = GetFontFamily(e.FontFamily); } if (e.FontSize.HasValue) { var fs = e.FontSize.Value; fs = Math.Max(0.004, fs); te.FontSize = fs; } if (e.FontStyle.HasValue) { te.FontStyle = ToFontStyle(e.FontStyle.Value); } if (e.FontWeight.HasValue) { te.FontWeight = ToFontWeight(e.FontWeight.Value); } if (e.Foreground.HasValue && e.Foreground != e.ForegroundInheritedOnly) { te.Foreground = GetBrushFromColor(e.Foreground.Value); } if (e.Background.HasValue && e.Background != e.BackgroundInheritedOnly) { te.Background = GetBrushFromColor(e.Background.Value); } } // now special properties if (e is Block b && wpf is swd.Block be) { if (b.Margin.HasValue) { be.Margin = ToThickness(b.Margin.Value); } if (b.Padding.HasValue) { be.Padding = ToThickness(b.Padding.Value); } if (b.BorderBrush.HasValue) { be.BorderBrush = new System.Windows.Media.SolidColorBrush(ToColor(b.BorderBrush.Value)); } if (b.BorderThickness.HasValue) { be.BorderThickness = ToThickness(b.BorderThickness.Value); } if (b.TextAlignment.HasValue) { be.TextAlignment = ToTextAlignment(b.TextAlignment.Value); } if (b.LineHeight.HasValue) { be.LineHeight = b.LineHeight.Value; } } if (e is Inline i && wpf is swd.Inline ie) { if (i.VerticalAlignment.HasValue) { ie.BaselineAlignment = ToBaselineAlignment(i.VerticalAlignment.Value); } } // finished rendering the attributes // now, render all children foreach (var child in e.Childs) { var childe = RenderRecursively(child); switch (wpf) { case swd.Figure figure: figure.Blocks.Add((swd.Block)childe); break; case swd.Floater floater: floater.Blocks.Add((swd.Block)childe); break; case swd.FlowDocument flowDocument: flowDocument.Blocks.Add((swd.Block)childe); break; case swd.List list: list.ListItems.Add((swd.ListItem)childe); break; case swd.ListItem listItem: listItem.Blocks.Add((swd.Block)childe); break; case swd.Section section: section.Blocks.Add((swd.Block)childe); break; case swd.Table table: table.RowGroups.Add((swd.TableRowGroup)childe); break; case swd.TableCell tableCell: tableCell.Blocks.Add((swd.Block)childe); break; case swd.TableRow tableRow: tableRow.Cells.Add((swd.TableCell)childe); break; case swd.TableRowGroup tableRowGroup: tableRowGroup.Rows.Add((swd.TableRow)childe); break; // now elements that can contain inlines case swd.Paragraph paragraph: paragraph.Inlines.Add((swd.Inline)childe); break; case swd.Span span: span.Inlines.Add((swd.Inline)childe); break; // now some specialties case swd.InlineUIContainer inlineUIContainer: if (inlineUIContainer.Child != null) { throw new InvalidOperationException($"{nameof(swd.InlineUIContainer)} can not contain more than one child"); } inlineUIContainer.Child = (System.Windows.UIElement)childe; break; case swd.BlockUIContainer blockUIContainer: if (blockUIContainer.Child != null) { throw new InvalidOperationException($"{nameof(swd.BlockUIContainer)} can not contain more than one child"); } blockUIContainer.Child = (System.Windows.UIElement)childe; break; default: throw new NotImplementedException(); } } if (AttachDomAsTags) { if (wpf is System.Windows.FrameworkContentElement conEle) { conEle.Tag = e; } else if (wpf is System.Windows.FrameworkElement uiEle) { uiEle.Tag = e; } } return(wpf); }
public static void LoadOpenXml(this FlowDocument doc, Stream stream) { using (WordprocessingDocument wdoc = WordprocessingDocument.Open(stream, false)) { //get default style XDocument xstyle, xdoc; StylesPart part = wdoc.MainDocumentPart.StyleDefinitionsPart; if (part == null) { //part = AddStylesPartToPackage(wdoc); xstyle = XDocument.Load(File.OpenRead("styles.xml")); } else { //using (StreamReader sr = new StreamReader(part.GetStream())) //{ xstyle = XDocument.Load(part.GetStream()); } var styles = from style in xstyle .Root .Descendants(w_style) let pPr = style .Elements(w_pPr) .FirstOrDefault() let rPr = style .Elements(w_rPr) .FirstOrDefault() select new { pStyleName = style.Attribute(w_styleId).Value, pName = style.Element(w_name).Attribute(w_val).Value, pPStyle = pPr, pRStyle = rPr }; foreach (var style in styles) { Style pStyle = style.pPStyle.ToWPFStyle(); pStyle.BasedOn = style.pRStyle.ToWPFStyle(); doc.Resources.Add(style.pStyleName, pStyle); } //} //get document using (StreamReader sr = new StreamReader(wdoc.MainDocumentPart.GetStream())) { xdoc = XDocument.Load(sr); var paragraphs = from par in xdoc .Root .Element(w_body) .Descendants(w_p) let par_style = par .Elements(w_pPr) .Elements(w_pStyle) .FirstOrDefault() let par_inline = par .Elements(w_pPr) .FirstOrDefault() let par_list = par .Elements(w_pPr) .Elements(w_numPr) .FirstOrDefault() select new { pElement = par, pStyle = par_style != null?par_style.Attribute(w_val).Value : (from d_style in xstyle .Root .Elements(w_style) where d_style.Attribute(w_type).Value == "paragraph" && d_style.Attribute(w_default).Value == "1" select d_style).First().Attribute(w_styleId).Value, pAttrs = par_inline, pRuns = par.Elements().Where(e => e.Name == w_r || e.Name == w_ins || e.Name == w_link || e.Name == w_numId || e.Name == w_numPr || e.Name == w_ilvl), pList = par_list }; foreach (var par in paragraphs) { Paragraph p = new Paragraph(); Style pStyle = par.pAttrs.ToWPFStyle(); if (par.pStyle != string.Empty) { pStyle.BasedOn = doc.Resources[par.pStyle] as Style; } p.Style = pStyle; var runs = from run in par.pRuns let run_style = run .Elements(w_rPr) .FirstOrDefault() let run_istyle = run .Elements(w_rPr) .Elements(w_rStyle) .FirstOrDefault() let run_graph = run .Elements(w_drawing) select new { pRun = run, pRunType = run.Name.LocalName, pStyle = run_istyle != null?run_istyle.Attribute(w_val).Value : string.Empty, pAttrs = run_style, pText = run.Descendants(w_t), pBB = run.Elements(w_br) != null, pExRelID = run.Name == w_link?run.Attribute(rels_id).Value : string.Empty, pGraphics = run_graph }; foreach (var run in runs) { Run r = new Run(); Style rStyle = run.pAttrs.ToWPFStyle(); if (run.pStyle != string.Empty) { rStyle.BasedOn = doc.Resources[run.pStyle] as Style; } r.Style = rStyle; r.Text = run.pText.ToString(txt => txt.Value); if (run.pRunType == "hyperlink") { ExternalRelationship er = (from rel in wdoc.MainDocumentPart.ExternalRelationships where rel.Id == run.pExRelID select rel).FirstOrDefault() as ExternalRelationship; if (er != null) { Hyperlink hl = new Hyperlink(r); hl.NavigateUri = er.Uri; p.Inlines.Add(hl); } } else { p.Inlines.Add(r); } var graphics = from graph in run.pGraphics let pBlip = graph .Descendants(a_blip) .Where(x => x.Attribute(rels_embed) != null) .FirstOrDefault() let pExtent = graph .Descendants(wp_extent) .FirstOrDefault() select new { pWidth = pExtent != null?pExtent.Attribute("cx").Value : "0", pHeight = pExtent != null?pExtent.Attribute("cy").Value : "0", pExRelID = pBlip != null?pBlip.Attribute(rels_embed).Value : string.Empty }; foreach (var graphic in graphics) { Console.WriteLine(graphic); } } if (par.pList != null) { int level = int.Parse(par.pList.Element(w_ilvl).Attribute(w_val).Value); List lst = doc.Blocks.LastBlock as List; ListItem nli = new ListItem(p); if (lst != null && lst.Tag != null && (int)lst.Tag < level) { List nlst = new List(nli); nlst.Tag = level; lst.ListItems.LastListItem.Blocks.Add(nlst); } else { lst = new List(nli); lst.Tag = level; doc.Blocks.Add(lst); } } else { doc.Blocks.Add(p); } } } } }
void RenderList(HTMLCollection children, List list) { foreach (var child in children) { if (child.TagName == "li") { var li = new ListItem(); var section = new Section(); li.Blocks.Add(section); Render(child, section); list.ListItems.Add(li); } } }
/// <summary> /// Inserts a List around a sequence of Blocks /// starting from firstBlock ending with lastBlock. /// the List must be empty and not inserted in a tree /// before the operation /// </summary> /// <param name="firstBlock"></param> /// <param name="lastBlock"></param> internal void Apply(Block firstBlock, Block lastBlock) { Invariant.Assert(this.Parent == null, "Cannot Apply List Because It Is Inserted In The Tree Already."); Invariant.Assert(this.IsEmpty, "Cannot Apply List Because It Is Not Empty."); Invariant.Assert(firstBlock.Parent == lastBlock.Parent, "Cannot Apply List Because Block Are Not Siblings."); TextContainer textContainer = this.TextContainer; textContainer.BeginChange(); try { // Wrap all block items into this List element this.Reposition(firstBlock.ElementStart, lastBlock.ElementEnd); // Add ListItem elements Block block = firstBlock; while (block != null) { ListItem listItem; if (block is List) { // To wrap List into list item we pull it into previous ListItem (if any) as sublist listItem = block.ElementStart.GetAdjacentElement(LogicalDirection.Backward) as ListItem; if (listItem != null) { // Wrap the List into preceding ListItem listItem.Reposition(listItem.ContentStart, block.ElementEnd); } else { // No preceding ListItem. Create new one listItem = new ListItem(); listItem.Reposition(block.ElementStart, block.ElementEnd); } } else { // To wrap paragraph into list item we need to create a new one // listItem = new ListItem(); listItem.Reposition(block.ElementStart, block.ElementEnd); // MS Word-like heuristic: clear margin from a paragraph before wrapping it into a list item // Note: using TextContainer to make sure that undo unit is created. block.ClearValue(Block.MarginProperty); block.ClearValue(Block.PaddingProperty); block.ClearValue(Paragraph.TextIndentProperty); } // Stop when the last paragraph is covered block = block == lastBlock ? null : (Block)listItem.ElementEnd.GetAdjacentElement(LogicalDirection.Forward); } // We need to set appropriate FlowDirection property on the new List and its paragraph children. // We take the FlowDirection value from the first paragraph's FlowDirection value. TextRangeEdit.SetParagraphProperty(this.ElementStart, this.ElementEnd, Paragraph.FlowDirectionProperty, firstBlock.GetValue(Paragraph.FlowDirectionProperty)); } finally { textContainer.EndChange(); } }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (textBox1.Text != "") { listBox1.Items.Clear(); List<string> newfr = new List<string>(); ListItem li = new ListItem(); Label newlabel; for (int i = 0; i < list_gf.Count(); i++) { newlabel = new Label(); newlabel.Height = 40; newlabel.HorizontalAlignment = HorizontalAlignment.Center; newlabel.Width = 234; newlabel.FontSize = 14; newlabel.Foreground = new SolidColorBrush(Colors.Blue); newlabel.FontWeight = FontWeights.ExtraBold; newlabel.Content = list_gf[i].group; listBox1.Items.Add(newlabel); for (int j = 0; j < list_gf[i].friends.Count(); j++) { if (list_gf[i].friends[j].Contains(textBox1.Text)) { newlabel = new Label(); newlabel.ContextMenu = new ContextMenu(); MenuItem mi = new MenuItem(); mi.Header = "Remove user"; mi.Click += new RoutedEventHandler(MiRemoveUser_Click); newlabel.ContextMenu.Items.Add(mi); mi = new MenuItem(); mi.Header = "View profile"; mi.Click += new RoutedEventHandler(MiViewProfile_Click); newlabel.ContextMenu.Items.Add(mi); newlabel.ToolTip = "Dorm!"; newlabel.Height = 40; newlabel.HorizontalAlignment = HorizontalAlignment.Center; newlabel.Width = 234; newlabel.FontSize = 14; newlabel.Content = list_gf[i].friends[j]; newlabel.MouseLeftButtonUp += new MouseButtonEventHandler(Label_MouseLeftButtonUp_1); newlabel.MouseEnter += new MouseEventHandler(newlabel_MouseEnter); listBox1.Items.Add(newlabel); } } } } }
private static void DumpRtfRecursively_List(List list, OutlinerNote outlinerNote) { foreach(var note in outlinerNote.SubNotes) { MemoryStream sectionStream = ExportToXaml_Printing.TransformFlowDocumentToSection(note.DefaultRichTextDocument); ListItem newItem = new ListItem(); Section section = XamlReader.Load(sectionStream) as Section; if (section == null) section = new Section(); newItem.Blocks.Add(section); list.ListItems.Add(newItem); if (outlinerNote.SubNotes.Count > 0) { List newList = new List(); list.FontFamily = UVOutliner.Settings.DefaultFontFamily; list.FontSize = UVOutliner.Settings.DefaultFontSize; newItem.Blocks.Add(newList); DumpRtfRecursively_List(newList, note); } } }
void AddList(string type, IEnumerable<XmlDocumentationElement> items) { List list = new List(); AddBlock(list); list.Margin = new Thickness(0, 5, 0, 5); if (type == "number") list.MarkerStyle = TextMarkerStyle.Decimal; else if (type == "bullet") list.MarkerStyle = TextMarkerStyle.Disc; var oldBlockCollection = blockCollection; try { foreach (var itemElement in items) { if (itemElement.Name == "listheader" || itemElement.Name == "item") { ListItem item = new ListItem(); blockCollection = item.Blocks; inlineCollection = null; foreach (var prop in itemElement.Children) { AddDocumentationElement(prop); } FlushAddedText(false); list.ListItems.Add(item); } } } finally { blockCollection = oldBlockCollection; } }
public Action AddToFlowDocument(IResumeDataObject rdo, IResumeFormatObject rfo, Win.FlowDocument flowDoc) { return(() => { var list = new List <Win.Block>(); // "Experience" header Win.Paragraph expTitlePara = new Win.Paragraph(); expTitlePara.Inlines.Add(new Win.Run("Experience")); expTitlePara.Margin = new System.Windows.Thickness(0, 20, 0, 20); expTitlePara.Foreground = rfo.HeaderColorBrush; expTitlePara.FontFamily = new FontFamily(rfo.HeaderFontName); expTitlePara.FontSize = rfo.HeaderFontSizeWindows; expTitlePara.Margin = rfo.HeaderMargin; list.Add(expTitlePara); for (int i = 0; i < rdo.ExperienceEntities.Count; i++) { var expItem = rdo.ExperienceEntities[i]; // Employer Name Win.Paragraph empName = new Win.Paragraph(new Win.Run(expItem.Employer)); empName.Foreground = rfo.JobInfoColorBrush; empName.FontFamily = new FontFamily(rfo.JobInfoFontName); empName.FontSize = rfo.JobInfoFontSizeWindows; list.Add(empName); // Title Win.Paragraph title = new Win.Paragraph(new Win.Run(expItem.Titles.FirstOrDefault())); title.Foreground = rfo.JobInfoColorBrush; title.FontFamily = new FontFamily(rfo.JobInfoFontName); title.FontSize = rfo.JobInfoFontSizeWindows; list.Add(title); // Dates Win.Paragraph dates = new Win.Paragraph(new Win.Run(expItem.StartDate + " - " + expItem.EndDate)); dates.Foreground = rfo.JobInfoColorBrush; dates.FontFamily = new FontFamily(rfo.JobInfoFontName); dates.FontSize = rfo.JobInfoFontSizeWindows; list.Add(dates); // List of experience items Win.List bullets = new Win.List(); for (int j = 0; j < rdo.ExperienceEntities[i].Details.Count; j++) { var item = new Win.ListItem(new Win.Paragraph(new Win.Run(rdo.ExperienceEntities[i].Details[j]))); bullets.ListItems.Add(item); item.FontFamily = new FontFamily(rfo.BodyFontName); item.FontSize = rfo.BodyFontSizeWindows; bullets.Margin = bulletMargin; list.Add(bullets); } } foreach (var item in list) { flowDoc.Blocks.Add(item); } }); }
public override DependencyObject Visit(Documentation.List list) { if (list.Type == ListType.Table) { var result = new Table(); result.Columns.Add(new TableColumn() { Width = new GridLength(1, GridUnitType.Star) }); result.Columns.Add(new TableColumn() { Width = new GridLength(3, GridUnitType.Star) }); result.RowGroups.Add(new TableRowGroup()); var header = new TableRow(); var termHeader = new TableCell(); if (list.Header?.Term.Count > 0) { termHeader.Blocks.AddRange(GetBlocks(list.Header?.Term.Select(e => e.Visit(this)))); } else { termHeader.Blocks.Add(new System.Windows.Documents.Paragraph(new Run("Term") { FontWeight = FontWeight.FromOpenTypeWeight(700) })); } header.Cells.Add(termHeader); var descripHeader = new TableCell(); if (list.Header?.Description.Count > 0) { descripHeader.Blocks.AddRange(GetBlocks(list.Header?.Description.Select(e => e.Visit(this)))); } else { descripHeader.Blocks.Add(new System.Windows.Documents.Paragraph(new Run("Description") { FontWeight = FontWeight.FromOpenTypeWeight(700) })); } header.Cells.Add(descripHeader); result.RowGroups[0].Rows.Add(header); foreach (var item in list.Children) { var row = new TableRow(); row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); if (item.Term.Count > 0) { row.Cells[0].Blocks.AddRange(GetBlocks(item.Term.Select(e => e.Visit(this)))); } if (item.Description.Count > 0) { row.Cells[1].Blocks.AddRange(GetBlocks(item.Description.Select(e => e.Visit(this)))); } result.RowGroups[0].Rows.Add(row); } return(result); } else { var result = new System.Windows.Documents.List { MarkerStyle = list.Type == ListType.Number ? TextMarkerStyle.Decimal : TextMarkerStyle.Disc }; if (_listLevel > 0) { result.Margin = new Thickness(0); } try { _listLevel++; result.ListItems.AddRange(list.Children.Select(i => { var item = new System.Windows.Documents.ListItem(); item.Blocks.AddRange(GetBlocks(i.Description.Select(e => e.Visit(this)))); return(item); })); return(result); } finally { _listLevel--; } } }
private Section _formatMarkup(string style, XElement markup) { if (markup == null) return null; var section = new Section(); if (style.NotEmpty()) { section.Style = _findStyle(style); } else { section.Padding = _zeroThickness; section.Margin = _zeroThickness; } Func<InlineCollection> inlines = () => { var para = section.Blocks.LastOrDefault() as Paragraph; if (para == null) { para = _createParagraph(); section.Blocks.Add(para); } return para.Inlines; }; foreach (var node in markup.Nodes()) { if (node is XText) { var text = ((XText)node).Value.Compact(); if (inlines().Count == 0) text = text.TrimStart(); if (text.NotEmpty()) { inlines().Add(new Run(text)); } } else if (node is XElement) { var elem = (XElement)node; var name = elem.Name.LocalName; if (name == "list") { var list = new List() { Style = _findStyle("@List") }; foreach (var markupItem in elem.Elements("item")) { var listItem = new ListItem { Margin = new Thickness(0, 0, 0, 12) }; listItem.Blocks.Add(_formatMarkup(null, markupItem)); list.ListItems.Add(listItem); } if (list.ListItems.Count > 0) { section.Blocks.Add(list); } } else if (name == "item" || name == "para") { section.Blocks.Add(_formatMarkup(null, elem)); } else if (name == "c" || name == "code" || name == "example") { var text = elem.Value.Compact(); if (text.NotEmpty()) { var span = new Span(new Run(text)) { Style = _findStyle("@Code") }; inlines().Add(span); } } else if (name == "see" || name == "seealso") { inlines().Add(_formatHyperlink(elem)); } } } return section; }