Skip to content

Instantly share code, notes, and snippets.

@huoxudong125
Created October 18, 2016 03:34
Show Gist options
  • Save huoxudong125/e8e684fafa4ae7f2479bc5aa053fdf43 to your computer and use it in GitHub Desktop.
Save huoxudong125/e8e684fafa4ae7f2479bc5aa053fdf43 to your computer and use it in GitHub Desktop.
WPF generate dynamic tabcontrol
namespace DynamicTabControl
{
public class Model
{
public string Header { get; set; }
public string Body { get; set; }
}
}
using System.Collections.ObjectModel;
namespace DynamicTabControl
{
public class ViewModel
{
public ObservableCollection<Model> Collection = new ObservableCollection<Model>();
public ViewModel()
{
Collection.Add(new Model() { Header = "Tab1", Body = "Content1" });
Collection.Add(new Model() { Header = "Tab2", Body = "Content2" });
Collection.Add(new Model() { Header = "Tab3", Body = "Content3" });
Collection.Add(new Model() { Header = "Tab4", Body = "Content4" });
}
}
}
<Window x:Class="DynamicTabControl.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igWindows="http://infragistics.com/Windows"
Title="MainWindow" Height="350" Width="525">
<Grid>
<igWindows:XamTabControl Name="xamTabControl" Theme="Metro" ItemsSource="{Binding Collection}">
<igWindows:XamTabControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Header}" />
</DataTemplate>
</igWindows:XamTabControl.ItemTemplate>
<igWindows:XamTabControl.ContentTemplate>
<DataTemplate>
<TextBox Text="{Binding Body}" />
</DataTemplate>
</igWindows:XamTabControl.ContentTemplate>
</igWindows:XamTabControl>
</Grid>
</Window>
------------------------Partialclass----------------------------------
namespace DynamicTabControl
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public ViewModel ViewColletion = new ViewModel();
public MainWindow()
{
InitializeComponent();
DataContext = ViewColletion;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment