Created
October 18, 2016 03:34
-
-
Save huoxudong125/e8e684fafa4ae7f2479bc5aa053fdf43 to your computer and use it in GitHub Desktop.
WPF generate dynamic tabcontrol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace DynamicTabControl | |
{ | |
public class Model | |
{ | |
public string Header { get; set; } | |
public string Body { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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