def get_text(self, text): tb = TextBlock() tb.Text = text tb.Width = self.canvas.ActualWidth tb.Height = 40 tb.FontSize = 30 tb.Background = SolidColorBrush(Colors.Black) tb.Foreground = SolidColorBrush(Colors.White) tb.TextAlignment = TextAlignment.Center return tb
def createTextBlockAndHyperlink(self, grid): textblock = TextBlock() textblock.TextWrapping = TextWrapping.Wrap textblock.Background = Brushes.AntiqueWhite textblock.TextAlignment = TextAlignment.Center textblock.Inlines.Add(Bold(Run("TextBlock"))) textblock.Inlines.Add(Run(" is designed to be ")) textblock.Inlines.Add(Italic(Run("lightweight"))) textblock.Inlines.Add(Run(", and is geared specifically at integrating ")) textblock.Inlines.Add(Italic(Run("small"))) textblock.Inlines.Add(Run(" portions of flow content into a UI. ")) link = Hyperlink(Run("A Hyperlink - Click Me")) def action(s, e): self.label.Content = "Hyperlink Clicked" link.Click += action textblock.Inlines.Add(link) SetGridChild(grid, textblock, 2, 2, "TextBlock")
def __init__(self, h): self.ctrl = Button() self.Initialize(h) if h.get('fontsize'): self.SetFontSize(h['fontsize']) if h.get('handler'): self.ctrl.Click += h['handler'] stack = StackPanel() stack.Orientation = Orientation.Vertical #Horizontal self.ctrl.Content = stack if h.get('image'): image = Image() image.Source = BitmapImage( System.Uri(h['image'], System.UriKind.Relative)) image.VerticalAlignment = VerticalAlignment.Center image.Stretch = Stretch.Fill #Stretch.None if h.get('size'): image.Height = float(h['size']) image.Width = float(h['size']) stack.Children.Add(image) if h.get('label'): text = TextBlock() text.Text = h['label'] text.TextAlignment = TextAlignment.Center stack.Children.Add(text)