Note that there are some explanatory texts on larger screens.

plurals
  1. POupdate listview from viewmodel
    primarykey
    data
    text
    <p>I am using MVVM and have a view which let users submit a message (like a blog) where the list "keeps populating with messages posted". When they click on save, this triggers the save command in the view model to save the message. My issue is, my gridview inside my listview doesnt update. I want to know if anyone can help me out. I'm at a point where I'm just going in circles. I know I'm missing some if not a lot of code but my brain cells are fried. </p> <p>my xaml:</p> <pre><code>&lt;Grid Name="grdMessage" HorizontalAlignment="Left" Width="816"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="auto"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="auto"&gt;&lt;/ColumnDefinition&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Grid.Row="0" Grid.Column="0" Text="Messages" HorizontalAlignment="Left" VerticalAlignment="Bottom" /&gt; &lt;ListView Name="lstMessage" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="762" Height="auto" Margin="15,0,0,0" ItemsSource="{Binding Path=MessageList}"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Width="462" Header="Message"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Path=Message, Mode=TwoWay}" TextAlignment="Left" HorizontalAlignment="Left" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Width="150" Header="Submitter"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Path=Submitter, Mode=TwoWay}" TextAlignment="Left" HorizontalAlignment="Left" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;TextBox Name="txtNewMessage" Grid.Row="4" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="762" Height="auto" TextWrapping="Wrap" AcceptsReturn="True" HorizontalScrollBarVisibility="Auto" Visibility="Collapsed" Text="{Binding Path=Message, Mode=TwoWay}"/&gt; &lt;Button Name="btnAddMessage" Grid.Row="6" Grid.Column="0" Content="Add" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,0,0" Command="{Binding Path=Save}" /&gt; </code></pre> <p></p> <p>my viewmodel:</p> <pre><code>Message message; </code></pre> <p><code>ObservableCollection&lt;Message&gt; messageList;</code><br> <code>RelayCommand save;</code></p> <pre><code> public ObservableCollection&lt;Message&gt; MessageList { get { if (messageList == null) messageList = new ObservableCollection&lt;Message&gt;(); } } public ICommand Save { get { return saveCmd ?? (save = new RelayCommand(parameter =&gt; SaveMessage())); } } void SaveMessage() { </code></pre> <p>this.MessageList.Add(this.Message); dataSource.AddMessage(message);</p> <pre><code> } Message Model string message; [DataMember] public int Submitter {get; set;} [DataMember] public string Message { get{ return(message);} set { if (message != value) { message = value; OnPropertyChanged("Message"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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