Note that there are some explanatory texts on larger screens.

plurals
  1. POUI Not updating from ObservableCollection called by a command from a seperate ViewModel
    text
    copied!<pre><code>private ObservableCollection&lt;ProjectItem&gt; _projectItems; public ObservableCollection&lt;ProjectItem&gt; DataItems { get { return _projectItems; } } public ProjectsPanelViewViewModel() { _projectItems = new ObservableCollection&lt;ProjectItem&gt;(); _createProjectCommand = new DelegateCommand(OnCreateProjectCommand); _saveProjectCommand = new DelegateCommand(OnSaveProjectCommand); } private void OnCreateProjectCommand() { _addProjectViewModel = new AddProjectViewModel(); AddProjectView view = new AddProjectView(); view.Show(); } private void OnSaveProjectCommand() { ProjectItemViewModel _vm = new ProjectItemViewModel(); _vm.ProjectName = ProjectName; _vm.ProjectDescription = ProjectDescription; var item = new ProjectItem(_vm); _projectItems.Add(item); } </code></pre> <p>XAML </p> <pre><code>&lt;UserControl.DataContext&gt; &lt;VM:ProjectsPanelViewViewModel/&gt; &lt;/UserControl.DataContext&gt; &lt;StackPanel Name="ProjectsPanel" Style="{DynamicResource FullLengthPanelStyle}" &gt; &lt;StackPanel Name="ProjectsHeader" Orientation="Horizontal" Margin="0,0,0,5"&gt; &lt;Label Style="{StaticResource TitleLabelStyleBlue}"&gt;projects&lt;/Label&gt; &lt;Button Name="AddProjects" Margin="10,5,0,0" Style="{StaticResource CircularGreyButtonStyle}" Content="+" ToolTip="Add a new project" Command="{Binding CreateProjectCommand}"/&gt; &lt;Button Name="ExpandProjects" Margin="10,5,0,0" Style="{StaticResource CircularGreyButtonStyle}" Content="&gt;" ToolTip="Expand projects"/&gt; &lt;/StackPanel&gt; &lt;ScrollViewer VerticalScrollBarVisibility="Visible"&gt; &lt;ItemsControl ItemsSource="{Binding DataItems}"/&gt; &lt;/ScrollViewer&gt; &lt;/StackPanel&gt; </code></pre> <p>When the OnCreateProjectCommand Opens it creates a window with 2 string fields, this then has a button that executes the OnSaveProjectCommand. The commands are executed fine, however the UI does not pick up that the new item has been added to the collection. (When debugging it is in there). If however you change the code from the OnSaveProjectCommand and put it into the OnCreateProjectCommand, and hardcode the simple string values, the UI is updated correctly from the observable collection.</p> <p>Can anyone give me some guidance as to why this is not working, and also the correct way that I should be spawning up a new window from this command. Should this be done with State Based view navigation from prism? We are already using this for modularisation and commanding. </p> <p>Thanks for the advice. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload