I have strange problem. Here's some code:
XAML of first view:
<UserControl.DataContext>
<vm:BendingTabViewModel/>
</UserControl.DataContext>
.......
<ItemsControl Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" ItemsSource="{Binding Path=DrawingToolViewModel.Grid, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid Width="200" Height="340" Margin="0,30,0,0"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Code (viemodel of first view):
//here I wrap DrawingToolViewModel
public DrawingToolViewModel DrawingToolViewModel { get; set; }
//here is the method that open new window
public void OpenRPlacementWindow(object obj)
{
BendingReinforcementPlacementWindowView
bendingReinforcementPlacementWindowView = new
BendingReinforcementPlacementWindowView();
//here i pass the same DrawingToolViewModel to viemodel of second view
bendingReinforcementPlacementWindowView.DataContext = bendingRPlacementWindowViewModel;
bendingReinforcementPlacementWindowView.ShowDialog();
}
XAML of second view:
<ItemsControl Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" ItemsSource="{Binding Path=DrawingToolViewModel.Grid, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row" Value="0"/>
<Setter Property="Grid.Column" Value="0"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid Width="200" Height="340" Margin="0,30,0,0"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Code (viemodel of second view):
private DrawingToolViewModel _drawingToolViewModel;
public DrawingToolViewModel DrawingToolViewModel
{
get { return _drawingToolViewModel; }
set { _drawingToolViewModel = value; }
}
Finnaly, code of DrawingToolViewModel:
private DrawingToolModel _drawingToolModel;
public DrawingToolModel DrawingToolModel
{
get { return _drawingToolModel; }
set { _drawingToolModel = value; }
}
public ObservableCollection<Grid> Grid
{
get { return DrawingToolModel.Grid; }
set
{
DrawingToolModel.Grid = value;
RaisePropertyChanged("Grid");
}
}
Problem:
In the first view i'm making some calculation, draw a rectangle, add it to Grid and add this Grid to ObservableCollection called "Grid". It shows in ItemsControl.
When i click button that open new window (this windows wraps the same drawing viewmodel) the rectangle shows in new window but disappear in first... Even when i closed second view and remake calculation and drawing the rectangle doesn't show.
Where i got wrong?