public override void ApplyFormattingAndLayout(SlotData slotData, SlotStyleData slotStyleData, TableLayoutItemInfo layout) { base.ApplyFormattingAndLayout(slotData, slotStyleData, layout); Brush background = null; Brush foreground = null; short fontID = -1; //IMPLEMENT: the rest of the properties in SlotData, SlotStyleData, and TableLayoutItemInfo if (layout != null) { // margins and paddings Margin = new Spacing(layout.LeftMargin, layout.TopMargin, layout.RightMargin, layout.BottomMargin); Padding = new Spacing(layout.LeftPadding, layout.TopPadding, layout.RightPadding, layout.BottomPadding); // cropping Crop = layout.CropStrategy; } if (slotData != null) { // background if (slotData.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(slotData.Background.Value, PaintStyleUse.Background); if (bgRes.Brush != null) { background = bgRes.Brush; } } // foreground if (slotData.Foreground.HasValue) { PaintStyleResult fgRes = ResolvePaintStyle(slotData.Foreground.Value, PaintStyleUse.Foreground); if (fgRes.Brush != null) { foreground = fgRes.Brush; } } // get font fontID = slotData.Font ?? -1; } if (slotStyleData != null) { // cropping Crop = slotStyleData.Crop; // background if (slotStyleData.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(slotStyleData.Background.Value, PaintStyleUse.Background); if (bgRes.Brush != null) { background = bgRes.Brush; } } // foreground if (slotStyleData.Foreground.HasValue) { PaintStyleResult fgRes = ResolvePaintStyle(slotStyleData.Foreground.Value, PaintStyleUse.Foreground); if (fgRes.Brush != null) { foreground = fgRes.Brush; } } // get font fontID = slotStyleData.Font; } // use parent foreground if needed if (foreground == null) { foreground = Atomic.Foreground; } // apply brushes Background = background; textControl.Foreground = foreground; // apply font if (fontID != -1) { FontReferencePaletteEntry fr = Atomic.FindCascadedPaletteItem(fontID) as FontReferencePaletteEntry; if (fr != null) { FontDefinition fd = fr.Resolve(Atomic.ParentNode.ApplicationID); if (fd != null) { fd.Apply(textControl); } } } // apply cropping, alignment, tick if ((Crop & CropStrategy.Wrap) == CropStrategy.Wrap) { textControl.TextWrapping = TextWrapping.Wrap; if ((Crop & CropStrategy.Tick) == CropStrategy.Tick) { textControl.TextTrimming = TextTrimming.WordEllipsis; } else { textControl.TextTrimming = TextTrimming.None; } } else if ((Crop & CropStrategy.Tick) == CropStrategy.Tick) { textControl.TextWrapping = TextWrapping.NoWrap; textControl.TextTrimming = TextTrimming.WordEllipsis; } else { textControl.TextWrapping = TextWrapping.NoWrap; textControl.TextTrimming = TextTrimming.None; } // set horizontal alignment (vertical one is done in layout) if ((Crop & CropStrategy.AlignLeft) == CropStrategy.AlignLeft) { textControl.TextAlignment = TextAlignment.Left; } else if ((Crop & CropStrategy.AlignHCenter) == CropStrategy.AlignHCenter) { textControl.TextAlignment = TextAlignment.Center; } else if ((Crop & CropStrategy.AlignRight) == CropStrategy.AlignRight) { textControl.TextAlignment = TextAlignment.Right; } }
public ScrollingTextBlock(View hostView, Node parentNode, BlockBase parentBlock, BlockDefinition definition, FieldList content, bool isRoot) : base(hostView, parentNode, parentBlock, definition, content, isRoot) { Caption = String.Empty; // parse content if (Content != null) { DisplayDataCollection ddc = DisplayData.Parse(Content); if ((ddc != null) && (ddc.Count > 0) && (ddc[0].DisplayType == DisplayType.String)) { Caption = (string)ddc[0].Data; } } // creating controls panel = new StackPanel(); panel.Orientation = Orientation.Vertical; wrapper = new ScrollViewer(); wrapper.Content = panel; // apply definition Brush fg = null; FontDefinition fd = null; if (Data != null) { // background if (Data.Background.HasValue) { PaintStyleResult bgRes = ResolvePaintStyle(Data.Background.Value); if (bgRes.Brush != null) { Background = bgRes.Brush; } } // foreground if (Data.Foreground.HasValue) { PaintStyleResult fgRes = ResolvePaintStyle(Data.Foreground.Value); fg = fgRes.Brush; } // apply font if (Data.Font.HasValue && (Data.Font.Value != -1)) { FontReferencePaletteEntry fr = FindCascadedPaletteItem(Data.Font.Value) as FontReferencePaletteEntry; if (fr != null) { fd = fr.Resolve(ParentNode.ApplicationID); } } // padding for text panel.Margin = new Thickness(DefaultPadding); } // apply text string[] parts = Caption.Split('\n'); foreach (string part in parts) { TextBlock paragraph = new TextBlock(); if (fg != null) { paragraph.Foreground = fg; } if (fd != null) { fd.Apply(paragraph); } paragraph.TextWrapping = TextWrapping.Wrap; if (!String.IsNullOrEmpty(part)) { paragraph.Text = part; } else { paragraph.Text = " "; } panel.Children.Add(paragraph); } // display text Children.Add(wrapper); }