WPF Button textblock

929Free 281 Reputation points
2020-07-08T02:33:46.717+00:00

I need to create two textblocks in the button control, but, I can't. Who can teach me? I need c# code. Thanks!

My code:

            Button btn_Click = new Button();

            btn_Click.Name = "Btn_1";
            btn_Click.Height = 100;
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,709 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dragon 81 Reputation points
    2020-07-08T02:54:28.853+00:00

    I think it like this:

    private void AddControls()
    {
        TextBlock textBlock1 = new TextBlock { Text = "Text 1", Width = 100, Height = 25};
        TextBlock textBlock2 = new TextBlock { Text = "Text 2", Width = 100, Height = 25 };
    
        StackPanel stackPanel = new StackPanel();
        stackPanel.Children.Add(textBlock1);
        stackPanel.Children.Add(textBlock2);
    
        Button button = new Button { Width = 250, Height = 60 };
        button.Content = stackPanel;
        gridMain.Children.Add(button);
    }
    

0 additional answers

Sort by: Most helpful