Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. public static class Building
  2. {
  3. public static readonly List<Beam> Beams = new List<Beam>();
  4. }
  5.  
  6. public class Beam
  7. {
  8. public string Story;
  9. public double Elevation;
  10. }
  11.  
  12. <ComboBox x:Name="cmbBuilding" ItemsSource="{Binding}">
  13. <ComboBox.ItemTemplate>
  14. <DataTemplate>
  15. <Grid Width="300">
  16. <TextBlock Width="150" Text="{Binding Path=Story }"/>
  17. <TextBlock Width="150" Text="{Binding Path=Elevation}"/>
  18. </Grid>
  19. </DataTemplate>
  20. </ComboBox.ItemTemplate>
  21. </ComboBox>
  22.  
  23. var b1 = new Beam { Elevation = 320, Story = "ST1" };
  24. var b2 = new Beam { Elevation = 640, Story = "ST2" };
  25. Building.Beams.Add(b1);
  26. Building.Beams.Add(b2);
  27.  
  28. <Grid>
  29. <ComboBox x:Name="cmbBuilding" Width="100" Height="25" ItemsSource="{Binding Path=Beams}">
  30. <ComboBox.ItemTemplate>
  31. <DataTemplate>
  32. <Grid Width="300">
  33. <TextBlock Width="150" Text="{Binding Path=Story}" HorizontalAlignment="Left" />
  34. <TextBlock Width="150" Text="{Binding Path=Elevation}" HorizontalAlignment="Right" />
  35. </Grid>
  36. </DataTemplate>
  37. </ComboBox.ItemTemplate>
  38. </ComboBox>
  39.  
  40. <Button Content="Add item" VerticalAlignment="Top" Click="Button_Click" />
  41. </Grid>
  42.  
  43. public partial class MainWindow : Window
  44. {
  45. Building building = new Building();
  46.  
  47. public MainWindow()
  48. {
  49. InitializeComponent();
  50.  
  51. building.Beams = new List<Beam>();
  52.  
  53. building.Beams.Add(new Beam
  54. {
  55. Elevation = 320,
  56. Story = "ST1"
  57. });
  58.  
  59. this.DataContext = building;
  60. }
  61.  
  62. private void Button_Click(object sender, RoutedEventArgs e)
  63. {
  64. var b1 = new Beam { Elevation = 320, Story = "ST1" };
  65. var b2 = new Beam { Elevation = 640, Story = "ST2" };
  66.  
  67. building.Beams.Add(b1);
  68. building.Beams.Add(b2);
  69.  
  70. cmbBuilding.Items.Refresh();
  71. }
  72. }
  73.  
  74. public class Building
  75. {
  76. public List<Beam> Beams
  77. {
  78. get;
  79. set;
  80. }
  81. }
  82.  
  83. public class Beam
  84. {
  85. public string Story
  86. {
  87. get;
  88. set;
  89. }
  90.  
  91. public double Elevation
  92. {
  93. get;
  94. set;
  95. }
  96. }
  97.  
  98. public class Beam
  99. {
  100. public string Story { get; set;}
  101. public double Elevation { get; set;}
  102. }
  103.  
  104. public static readonly ObservableCollection<Beam> Beams
  105. = new ObservableCollection<Beam>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement