Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Building
- {
- public static readonly List<Beam> Beams = new List<Beam>();
- }
- public class Beam
- {
- public string Story;
- public double Elevation;
- }
- <ComboBox x:Name="cmbBuilding" ItemsSource="{Binding}">
- <ComboBox.ItemTemplate>
- <DataTemplate>
- <Grid Width="300">
- <TextBlock Width="150" Text="{Binding Path=Story }"/>
- <TextBlock Width="150" Text="{Binding Path=Elevation}"/>
- </Grid>
- </DataTemplate>
- </ComboBox.ItemTemplate>
- </ComboBox>
- var b1 = new Beam { Elevation = 320, Story = "ST1" };
- var b2 = new Beam { Elevation = 640, Story = "ST2" };
- Building.Beams.Add(b1);
- Building.Beams.Add(b2);
- <Grid>
- <ComboBox x:Name="cmbBuilding" Width="100" Height="25" ItemsSource="{Binding Path=Beams}">
- <ComboBox.ItemTemplate>
- <DataTemplate>
- <Grid Width="300">
- <TextBlock Width="150" Text="{Binding Path=Story}" HorizontalAlignment="Left" />
- <TextBlock Width="150" Text="{Binding Path=Elevation}" HorizontalAlignment="Right" />
- </Grid>
- </DataTemplate>
- </ComboBox.ItemTemplate>
- </ComboBox>
- <Button Content="Add item" VerticalAlignment="Top" Click="Button_Click" />
- </Grid>
- public partial class MainWindow : Window
- {
- Building building = new Building();
- public MainWindow()
- {
- InitializeComponent();
- building.Beams = new List<Beam>();
- building.Beams.Add(new Beam
- {
- Elevation = 320,
- Story = "ST1"
- });
- this.DataContext = building;
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- var b1 = new Beam { Elevation = 320, Story = "ST1" };
- var b2 = new Beam { Elevation = 640, Story = "ST2" };
- building.Beams.Add(b1);
- building.Beams.Add(b2);
- cmbBuilding.Items.Refresh();
- }
- }
- public class Building
- {
- public List<Beam> Beams
- {
- get;
- set;
- }
- }
- public class Beam
- {
- public string Story
- {
- get;
- set;
- }
- public double Elevation
- {
- get;
- set;
- }
- }
- public class Beam
- {
- public string Story { get; set;}
- public double Elevation { get; set;}
- }
- public static readonly ObservableCollection<Beam> Beams
- = new ObservableCollection<Beam>();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement