public override UIElement BuildElement(DisplayBlock.DisplayBlock displayBlock) { var pictureBlock = displayBlock as DisplayBlock.PictureBlock; var bitmap = new Media.Imaging.BitmapImage(); using (var ms = new MemoryStream(Convert.FromBase64String(pictureBlock.Details.Base64Image))) { bitmap.BeginInit(); bitmap.CacheOption = Media.Imaging.BitmapCacheOption.OnLoad; // here bitmap.StreamSource = ms; bitmap.EndInit(); } var image = new Image { Height = pictureBlock.Height, Width = pictureBlock.Width, Source = bitmap, Stretch = Media.Stretch.None }; Canvas.SetTop(image, pictureBlock.Top); Canvas.SetLeft(image, pictureBlock.Left); Panel.SetZIndex(image, pictureBlock.ZIndex); return(image); }
public override UIElement BuildElement(DisplayBlock.DisplayBlock displayBlock) { var textBlock = displayBlock as DisplayBlock.TextBlock; var bc = new Media.BrushConverter(); var label = new TextBlock { Height = textBlock.Height, Width = textBlock.Width, Text = textBlock.Details.Text, FontSize = textBlock.Details.FontSize, FontFamily = new Media.FontFamily(textBlock.Details.FontName), FontWeight = textBlock.Details.Bold ? FontWeights.Bold : FontWeights.Normal, FontStyle = textBlock.Details.Italic ? FontStyles.Italic : FontStyles.Normal, LineHeight = textBlock.Details.FontSize * textBlock.Details.FontIndex, TextAlignment = textBlock.Details.Align == DisplayBlock.Align.Left ? TextAlignment.Left : textBlock.Details.Align == DisplayBlock.Align.Center ? TextAlignment.Center : textBlock.Details.Align == DisplayBlock.Align.Right ? TextAlignment.Right : TextAlignment.Left }; if (ColorConverter.TryToParseRGB(textBlock.Details.BackColor, out string colorHex)) { label.Background = (Media.Brush)bc.ConvertFrom(colorHex); } if (ColorConverter.TryToParseRGB(textBlock.Details.TextColor, out colorHex)) { label.Foreground = (Media.Brush)bc.ConvertFrom(colorHex); } Canvas.SetTop(label, textBlock.Top); Canvas.SetLeft(label, textBlock.Left); Panel.SetZIndex(label, textBlock.ZIndex); return(label); }
public override UIElement BuildElement(DisplayBlock.DisplayBlock displayBlock) { var datetimeBlock = displayBlock as DisplayBlock.DateTimeBlock; var bc = new Media.BrushConverter(); var label = new TextBlock { Height = datetimeBlock.Height, Width = datetimeBlock.Width, FontSize = datetimeBlock.Details.FontSize, FontFamily = new Media.FontFamily(datetimeBlock.Details.FontName), FontWeight = datetimeBlock.Details.Bold ? FontWeights.Bold : FontWeights.Normal, FontStyle = datetimeBlock.Details.Italic ? FontStyles.Italic : FontStyles.Normal, LineHeight = datetimeBlock.Details.FontSize * datetimeBlock.Details.FontIndex, TextAlignment = datetimeBlock.Details.Align == DisplayBlock.Align.Left ? TextAlignment.Left : datetimeBlock.Details.Align == DisplayBlock.Align.Center ? TextAlignment.Center : datetimeBlock.Details.Align == DisplayBlock.Align.Right ? TextAlignment.Right : TextAlignment.Left }; var dispatcher = Dispatcher.CurrentDispatcher; if (datetimeBlock.Details.Format != null) { var timerManager = new TimerManager(); timerManager.Subscribe(() => { dispatcher.Invoke(() => label.Text = DateTime.Now.ToString(datetimeBlock.Details.Format.ShowtimeFormat)); }); } if (ColorConverter.TryToParseRGB(datetimeBlock.Details.BackColor, out string colorHex)) { label.Background = (Media.Brush)bc.ConvertFrom(colorHex); } if (ColorConverter.TryToParseRGB(datetimeBlock.Details.TextColor, out colorHex)) { label.Foreground = (Media.Brush)bc.ConvertFrom(colorHex); } Canvas.SetTop(label, datetimeBlock.Top); Canvas.SetLeft(label, datetimeBlock.Left); Panel.SetZIndex(label, datetimeBlock.ZIndex); return(label); }
public override UIElement BuildElement(DisplayBlock.DisplayBlock displayBlock) { var tableBlock = displayBlock as DisplayBlock.TableBlock; var rows = tableBlock.Details.Cells.GroupBy(c => c.Row).OrderBy(r => r.Key); var headerStyle = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader)); foreach (var style in GetRowStyleSetters(tableBlock.Details.HeaderDetails, tableBlock.Details.FontSize, tableBlock.Details.FontName)) { headerStyle.Setters.Add(style); } var rowStyle = new Style(typeof(DataGridRow)); var oddTrigger = new Trigger() { Property = DataGridRow.AlternationIndexProperty, Value = 1 }; var evenTrigger = new Trigger() { Property = DataGridRow.AlternationIndexProperty, Value = 0 }; rowStyle.Triggers.Add(oddTrigger); rowStyle.Triggers.Add(evenTrigger); var rowHeight = (tableBlock.Height - tableBlock.Details.FontSize * tableBlock.Details.FontIndex) / (rows.Count() - 1); foreach (var style in GetRowStyleSetters(tableBlock.Details.OddRowDetails, tableBlock.Details.FontSize, tableBlock.Details.FontName)) { oddTrigger.Setters.Add(style); } oddTrigger.Setters.Add(new Setter(FrameworkElement.HeightProperty, (double)rowHeight)); foreach (var style in GetRowStyleSetters(tableBlock.Details.EvenRowDetails, tableBlock.Details.FontSize, tableBlock.Details.FontName)) { evenTrigger.Setters.Add(style); } evenTrigger.Setters.Add(new Setter(FrameworkElement.HeightProperty, (double)rowHeight)); var dataGrid = new DataGrid { HeadersVisibility = DataGridHeadersVisibility.Column, Height = tableBlock.Height, Width = tableBlock.Width, VerticalAlignment = VerticalAlignment.Stretch, BorderThickness = new Thickness(0), RowHeight = 50, GridLinesVisibility = DataGridGridLinesVisibility.None, AlternationCount = 2, ColumnHeaderStyle = headerStyle, RowStyle = rowStyle }; var columnCount = tableBlock.Details.Cells.Max(c => c.Column) + 1; var header = rows.FirstOrDefault().OrderBy(c => c.Column).ToArray(); for (int i = 0; i < columnCount; i++) { var name = $"Column{i}"; dataGrid.Columns.Add(new DataGridTextColumn { Header = header[i].Value, Binding = new Binding(name), Width = new DataGridLength(1, DataGridLengthUnitType.Star) }); } foreach (var row in rows.Skip(1)) { dynamic tableRow = new ExpandoObject(); var i = 0; foreach (var cell in row.OrderBy(c => c.Column)) { var name = $"Column{i}"; ((IDictionary <string, object>)tableRow)[name] = cell.Value; i++; } dataGrid.Items.Add(tableRow); } Canvas.SetTop(dataGrid, tableBlock.Top); Canvas.SetLeft(dataGrid, tableBlock.Left); Panel.SetZIndex(dataGrid, tableBlock.ZIndex); return(dataGrid); }