WPF Implementation tab Effects (2)--Dynamic Add avalondock tab

Source: Internet
Author: User

Brief introduction

In the previous article, we used Avalondock to implement a tab similar to VS (or a browser's tab) effect. But we are implementing it through XAML code.
Now we are trying to implement the dynamic addition of the tab through C # code.

modifying XAML code

In the XAML code for the previous article, add the following code:

 <grid.rowdefinitions>            <rowdefinition Height="+"></rowdefinition>            <rowdefinition></rowdefinition>        </grid.rowdefinitions>        <menu Name="Menu1"grid.row="0">              <MenuItem Name="Item_addnew" Header="Add new tab"  click ="Item_addnew_click"></MenuItem>        </Menu>

In XAML code, add the Name property to Layoutdocumentpane.

<avalon:LayoutDocumentPane x:Name="layOutPane"  DockWidth="300">

In our design, we do the work of dynamically adding tabs by clicking on the "Add New tab" menu. As a result, dynamically added C # code needs to be written in Item_addnew_click.

Write C # code for dynamic Additions

Open the MainWindow.xaml.cs file and add the following reference to the code header:

using Xceed.Wpf.AvalonDock;using Xceed.Wpf.AvalonDock.Layout;

Then write the menu click events.

int0;        privatevoiditem_AddNew_Click(object sender, RoutedEventArgs e)        {            clickCount++;            new"新选项卡"+clickCount };            new TextBox() { Text="这是第"+clickCount+"个新选项卡"};            layOutPane.Children.Add(layOutAnc);        }

To run the program, the effect is as follows:
  
We have implemented the dynamic addition of tabs.

WPF Implementation tab Effects (2)--Dynamic Add avalondock tab

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.