WPF Button textblock

929Free 661 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;
Developer technologies | Windows Presentation Foundation
0 comments No comments

Answer accepted by question author

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);
}

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.