locked
Dynamic border of textlblock image RRS feed

  • Question

  •  

    Border brdr = new Border();
    brdr.BorderThickness = "1";
    brdr.BorderBrush= "Gray";
    brdr.Background = "Red";
    brdr.CornerRadius = "5";

    how to apply this border on an Image or Textblock in class file

    anybody help me out

    thanks in advance. 

    Monday, June 30, 2008 8:35 AM

Answers

  • this sample adds a TextBlock to a Border and then Border to a canvas

    Border brdr = new Border();
    brdr.BorderThickness = new Thickness(1);
    brdr.BorderBrush = new SolidColorBrush(Colors.Gray);
    brdr.Background = new SolidColorBrush(Colors.Red);
    brdr.CornerRadius = new CornerRadius(5);
    TextBlock txt = new TextBlock();
    txt.Padding = new Thickness(2);
    txt.Text = "Some text";
    brdr.Child = txt;
    c1.Children.Add(brdr);//c1 is a canvas

    Monday, June 30, 2008 8:58 AM

All replies

  •  Do you want to deal with the stroke?

                Rectangle k = new Rectangle();
                k.Stroke = new SolidColorBrush(Colors.Blue);
                k.Fill = new SolidColorBrush(Colors.Green);
                LayoutRoot.Children.Add(k);

    Monday, June 30, 2008 8:51 AM
  • this sample adds a TextBlock to a Border and then Border to a canvas

    Border brdr = new Border();
    brdr.BorderThickness = new Thickness(1);
    brdr.BorderBrush = new SolidColorBrush(Colors.Gray);
    brdr.Background = new SolidColorBrush(Colors.Red);
    brdr.CornerRadius = new CornerRadius(5);
    TextBlock txt = new TextBlock();
    txt.Padding = new Thickness(2);
    txt.Text = "Some text";
    brdr.Child = txt;
    c1.Children.Add(brdr);//c1 is a canvas

    Monday, June 30, 2008 8:58 AM
  • I want to add a textblock dynamically like

    Textblock tb = new TextBlock();

    Here I want to apply some border arround this textblock how can i do this ???????????????????????????

    LayoutRoot.Children.Add(tb);

     

    please solve my prob

    thanks 

    Monday, June 30, 2008 9:01 AM
  • you have to wrap Border around a control. so you have to create a border and add textblock to that border as a child and add border to the container. the above code sample does just that

    Monday, June 30, 2008 9:08 AM
  • Dear How can I apply border in Image. Like you have alread write a code.

     

    please tell me.

    thanks 

     

     

    Monday, June 30, 2008 10:03 AM
  • Not sure I understand, if you want to place border around an Image jsut create Image and add it to border instead of Textblock

    Monday, June 30, 2008 10:05 AM