Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating bound ObservableCollection in ViewModel using MVVM Pattern
    primarykey
    data
    text
    <p>I'm new to MVVM, just recently started my first project following the MVVM pattern. I have an issue trying to validate an ObservableCollection using the IDataErrorInfo Interface. My ObservableCollection looks like this:</p> <pre><code>ObservableCollection&lt;Magazine&gt; magazineRepository; public ObservableCollection&lt;Magazine&gt; MagazineRepository { get { return magazineRepository; } set { if (value != null) { bladRepository = value; OnPropertyChanged("MagazineRepository"); } } } </code></pre> <p>And my XAML like this:</p> <pre><code>&lt;ListBox x:Name="listMagazineRepository" Grid.ColumnSpan="2" ItemsSource="{Binding}" DataContext="{Binding MagazineRepository}" DisplayMemberPath="Navn" SelectedItem="{Binding Path=SelectedItem}"/&gt; &lt;TextBox x:Name="txtName" Grid.Row="1" Grid.Column="0" Text="{Binding ElementName=listMagazineRepository, Path=SelectedItem.Navn, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /&gt; &lt;TextBox x:Name="txtPrice" Grid.Row="2" Grid.Column="0" Text="{Binding ElementName=listMagazineRepository, Path=SelectedItem.Pris, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" /&gt; </code></pre> <p>It's just a simple listBox containing objects, when you select an item, the selected objects properties is displayed in the textboxes, and is then bound to the listbox object.</p> <p>My Problem is, that when I set my code up like this, the only way I can figure out how to validate my data is in the Domain Model, which really isn't a good practise, I'd like to validate in the ViewModel before it gets there. Basically I want to validate each property in the MagazineRepository, in the ViewModel, How would you go about doing this?</p> <p>PS: I'm new to posting on this board (and programming boards in general) if my question is lacking information, please let me know and I will supply the needed details. </p> <p>Thanks a lot. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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