Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="Importer.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Product Group" Height="350" Width="721"
- xmlns:VM="clr-namespace:Importer.ViewModels">
- <Window.DataContext>
- <VM:ProductsViewModel />
- </Window.DataContext>
- <Grid Margin="0,0,0.4,0.4">
- <DataGrid x:Name="dgGrid" ColumnWidth="Auto" Margin="10,10,0,0" VerticalAlignment="Top"
- ItemsSource="{Binding ProductCollection}" HorizontalAlignment="Left" AutoGenerateColumns="False" >
- <DataGrid.Columns>
- <DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="150"/>
- <DataGridTextColumn Binding="{Binding Description}" Header="Description" Width="400" />
- </DataGrid.Columns>
- </DataGrid>
- <Button x:Name="btnAddProjectGroup" Content="Add Project Group" HorizontalAlignment="Left" Margin="10,277,0,0" VerticalAlignment="Top" Width="135" Click="btnAddProjectGroup_Click"/>
- </Grid>
- </Window>
- public partial class MainWindow : Window
- {
- ProductsViewModel m_VM = new ProductsViewModel();
- public MainWindow()
- {
- InitializeComponent();
- }
- private void btnAddProjectGroup_Click(object sender, RoutedEventArgs e)
- {
- // Open new window here to add a new project group
- AddProductGroup dlg = new AddProductGroup(m_VM);
- dlg.ShowDialog();
- }
- }
- public partial class AddProductGroup : Window
- {
- ProductGroupBindable newProduct = new ProductGroupBindable();
- ProductsViewModel viewModel = null;
- public AddProductGroup(ProductsViewModel vm)
- {
- viewModel = vm;
- InitializeComponent();
- }
- private void btnOK_Click(object sender, RoutedEventArgs e)
- {
- newProduct.Id = System.Guid.NewGuid();
- newProduct.Name = txtName.Text;
- newProduct.Description = txtDescription.Text;
- viewModel.AddProduct(newProduct);
- this.Close();
- }
- }
- private ObservableCollection<ProductGroupBindable> m_ProductCollection;
- public ProductsViewModel()
- {
- if (m_ProductCollection == null)
- m_ProductCollection = new ObservableCollection<ProductGroupBindable>();
- }
- public ObservableCollection<ProductGroupBindable> ProductCollection
- {
- get
- {
- return m_ProductCollection;
- }
- set
- {
- m_ProductCollection = value;
- }
- }
- private ObservableCollection<ProductGroupBindable> Test()
- {
- m_ProductCollection.Add(new ProductGroupBindable { Description = "etc", Name = "test12" });
- m_ProductCollection.Add(new ProductGroupBindable { Description = "etc", Name = "test123" });
- return ProductCollection;
- }
- public void AddProduct(ProductGroupBindable newProduct)
- {
- m_ProductCollection.Add(newProduct);
- //NotifyPropertyChanged("ProductCollection");
- }
- <Window.DataContext>
- <VM:ProductsViewModel />
- </Window.DataContext>
- ProductsViewModel m_VM = new ProductsViewModel();
- AddProductGroup dlg = new AddProductGroup(this.DataContext as ProductsViewModel);
- public MainWindow()
- {
- InitializeComponent();
- this.DataContext = m_VM;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement