none
TextBlock added programmatically doesn't show up RRS feed

  • Question

  • i have a function that programmatically geneates multiple Rectangle , draw them onto Panel, and show in DataGridCell

    it is working fine

            Rectangle DrawPackage(Panel img, Placement placement)
            {
                var bookpk = data...;
    
                var imgPack = new Rectangle
                {
                    Height = placement.Length,
                    Width = placement.Width,
                    Stroke = Brushes.Black,
                    StrokeThickness = 2,
                    Fill = new SolidColorBrush(bookpk.Color),
                };
                
                Canvas.SetTop(imgPack, placement.Position.Y);
                Canvas.SetLeft(imgPack, placement.Position.X);
    
                img.Children.Add(imgPack);
    
                return imgPack;
            }
    


    now for each Rectangle i added, i want to add a TextBlock, but this TextBlock doesn't show

                var imgPack = new Rectangle
                {...};
                
                ...
                img.Children.Add(imgPack);
    
                var tb = new TextBlock
                {
                    Height = placement.Length,
                    Width = placement.Width,
                    Text = bookpk.Index.ToString(),
                    IsHitTestVisible = false,
                };
                Canvas.SetTop(tb, placement.Position.Y);
                Canvas.SetLeft(tb, placement.Position.X);
                Canvas.SetZIndex(tb, Canvas.GetZIndex(imgPack) + 10);
                img.Children.Add(tb);
    

    what do i missing to make this textblock show up?

    Thursday, April 19, 2018 10:11 AM

Answers

  • figured out

    they working good, it just that the text is too small as i put the whole Panel in a ViewBox zoom out very high

    when i set the fontSize = 200

    i can see them

    just have to figure out how to scale up the fontSize 

    • Marked as answer by Kelmen Thursday, April 19, 2018 10:33 AM
    Thursday, April 19, 2018 10:33 AM

All replies

  • i test by setting the textblock/textbox background to a color

    Text = "TEST"

    Background = new SolidColorBrush(Colors.Red)

    i can see the text red rectangle, but no text, even i fixed it as the code above

    Thursday, April 19, 2018 10:27 AM
  • figured out

    they working good, it just that the text is too small as i put the whole Panel in a ViewBox zoom out very high

    when i set the fontSize = 200

    i can see them

    just have to figure out how to scale up the fontSize 

    • Marked as answer by Kelmen Thursday, April 19, 2018 10:33 AM
    Thursday, April 19, 2018 10:33 AM