WPF Add control Panel in VB.NET

In this article you will learn that how you can add control in a Panel.
  • 3752

Here in this article I am explaining that how you can add controls to a panel. As we have used StackPanel. StackPanel arranges the content either vertically or horizontally. The by default setting of the StcakPanel is Vertical. StackPanel generally Stacks the element. Firstly we will add a StackPanel. In StackPanel we will add a TextBlock and a Tab control. When you clicked the Tab control, a Button control should be added to the StackPanel. The Implementation  needs a StackPanel, TextBlock and Tab control.

Getting Started

  • Simply create a new WPF application.
  • Drag a StackPanel, TextBlock and a Tab control on MainWindow. Your window will look like below.

  • your MainWindow.xaml will look like below.

    <Window x:Class="MainWindow"
        Title="MainWindow" Height="290" Width
            <TextBlock Name="txt" FontSize="16">How to add control to a Panel</TextBlock>
                <TabItem MouseLeftButtonUp="AddButton">
                    <TabItem.Header>Click for Add Control</TabItem.Header>
            <StackPanel Name="stackpan1"></StackPanel>
  • Then attach the below code in code behind file.

    Private addbtn As System.Windows.Controls.Button, addbtn1 AsSystem.Windows.Controls.Button
         addbtn2 As System.Windows.Controls.Button,addbtn3 AsSystem.Windows.Controls.Button
         Private Sub btnAdd(sender As Object, e As MouseButtonEventArgs)
            addbtn = New Button()
            addbtn.Content = "i have added a New Button"
        End Sub
  • Now run your application.




In this article you learned that how you can add control in a Panel in WPF.


More Articles

© 2020 DotNetHeaven. All rights reserved.