Guest User

Untitled

a guest
Apr 24th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. How to create tab-able content in WPF/C#?
  2. <Page.DataContext>
  3. <Samples:TabBindingViewModels />
  4. </Page.DataContext>
  5.  
  6. <Grid>
  7. <Grid.Resources>
  8. <DataTemplate x:Key="ContentTemplate"
  9. DataType="{x:Type Samples:TabBindingViewModel}">
  10. <TextBlock Text="{Binding Content}"/>
  11. </DataTemplate>
  12. </Grid.Resources>
  13. <TabControl ContentTemplate="{StaticResource ContentTemplate}"
  14. DisplayMemberPath="Header" ItemsSource="{Binding Items}" />
  15. </Grid>
  16.  
  17. public class TabBindingViewModels
  18. {
  19. public TabBindingViewModels()
  20. {
  21. Items = new ObservableCollection<TabBindingViewModel>
  22. {
  23. new TabBindingViewModel(1),
  24. new TabBindingViewModel(2),
  25. new TabBindingViewModel(3),
  26. };
  27. }
  28.  
  29. public IEnumerable<TabBindingViewModel> Items { get; private set; }
  30. }
  31.  
  32. public class TabBindingViewModel
  33. {
  34. public TabBindingViewModel() : this(0)
  35. {
  36. }
  37.  
  38. public TabBindingViewModel(int n)
  39. {
  40. Header = "I'm the header: " + n.ToString(CultureInfo.InvariantCulture);
  41. Content = "I'm the content: " + n.ToString(CultureInfo.InvariantCulture);
  42. }
  43.  
  44. public string Header { get; set; }
  45. public string Content { get; set; }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment