Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <Window x:Class="Importer.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="Product Group" Height="350" Width="721"
  5. xmlns:VM="clr-namespace:Importer.ViewModels">
  6. <Window.DataContext>
  7. <VM:ProductsViewModel />
  8. </Window.DataContext>
  9. <Grid Margin="0,0,0.4,0.4">
  10. <DataGrid x:Name="dgGrid" ColumnWidth="Auto" Margin="10,10,0,0" VerticalAlignment="Top"
  11. ItemsSource="{Binding ProductCollection}" HorizontalAlignment="Left" AutoGenerateColumns="False" >
  12. <DataGrid.Columns>
  13. <DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="150"/>
  14. <DataGridTextColumn Binding="{Binding Description}" Header="Description" Width="400" />
  15. </DataGrid.Columns>
  16. </DataGrid>
  17. <Button x:Name="btnAddProjectGroup" Content="Add Project Group" HorizontalAlignment="Left" Margin="10,277,0,0" VerticalAlignment="Top" Width="135" Click="btnAddProjectGroup_Click"/>
  18. </Grid>
  19. </Window>
  20.  
  21. public partial class MainWindow : Window
  22. {
  23. ProductsViewModel m_VM = new ProductsViewModel();
  24.  
  25. public MainWindow()
  26. {
  27. InitializeComponent();
  28. }
  29.  
  30.  
  31. private void btnAddProjectGroup_Click(object sender, RoutedEventArgs e)
  32. {
  33. // Open new window here to add a new project group
  34. AddProductGroup dlg = new AddProductGroup(m_VM);
  35.  
  36. dlg.ShowDialog();
  37. }
  38. }
  39.  
  40. public partial class AddProductGroup : Window
  41. {
  42. ProductGroupBindable newProduct = new ProductGroupBindable();
  43. ProductsViewModel viewModel = null;
  44.  
  45. public AddProductGroup(ProductsViewModel vm)
  46. {
  47. viewModel = vm;
  48.  
  49. InitializeComponent();
  50. }
  51.  
  52. private void btnOK_Click(object sender, RoutedEventArgs e)
  53. {
  54. newProduct.Id = System.Guid.NewGuid();
  55. newProduct.Name = txtName.Text;
  56. newProduct.Description = txtDescription.Text;
  57.  
  58. viewModel.AddProduct(newProduct);
  59. this.Close();
  60. }
  61. }
  62.  
  63. private ObservableCollection<ProductGroupBindable> m_ProductCollection;
  64.  
  65.  
  66. public ProductsViewModel()
  67. {
  68. if (m_ProductCollection == null)
  69. m_ProductCollection = new ObservableCollection<ProductGroupBindable>();
  70. }
  71.  
  72.  
  73. public ObservableCollection<ProductGroupBindable> ProductCollection
  74. {
  75.  
  76. get
  77. {
  78. return m_ProductCollection;
  79. }
  80. set
  81. {
  82. m_ProductCollection = value;
  83. }
  84.  
  85. }
  86.  
  87. private ObservableCollection<ProductGroupBindable> Test()
  88. {
  89. m_ProductCollection.Add(new ProductGroupBindable { Description = "etc", Name = "test12" });
  90. m_ProductCollection.Add(new ProductGroupBindable { Description = "etc", Name = "test123" });
  91.  
  92. return ProductCollection;
  93. }
  94.  
  95. public void AddProduct(ProductGroupBindable newProduct)
  96. {
  97. m_ProductCollection.Add(newProduct);
  98. //NotifyPropertyChanged("ProductCollection");
  99. }
  100.  
  101. <Window.DataContext>
  102. <VM:ProductsViewModel />
  103. </Window.DataContext>
  104.  
  105. ProductsViewModel m_VM = new ProductsViewModel();
  106.  
  107. AddProductGroup dlg = new AddProductGroup(this.DataContext as ProductsViewModel);
  108.  
  109. public MainWindow()
  110. {
  111. InitializeComponent();
  112. this.DataContext = m_VM;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement