Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Application framework is binding to the model?
    primarykey
    data
    text
    <p>today I examinted WAP from codeplex a bit and saw this:</p> <p>BookListView.xaml:</p> <pre><code>&lt;ListView ItemsSource="{Binding Books}" SelectedItem="{Binding SelectedBook}" SelectionChanged="ListViewSelectionChanged"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Title}" Header="{x:Static p:Resources.Title}" Width="250"/&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding Author}" Header="{x:Static p:Resources.Author}" Width="150"/&gt; &lt;GridViewColumn DisplayMemberBinding="{Binding PublishDate, StringFormat=d}" Header="{x:Static p:Resources.PublishDate}" Width="100"/&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; </code></pre> <p><strong>UPDATE</strong>:</p> <pre><code>[Export(typeof(IBookListView))] public partial class BookListView : UserControl, IBookListView { public BookListView() { InitializeComponent(); } private BookListViewModel ViewModel { get { return DataContext as BookListViewModel; } } private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (Book book in e.RemovedItems) { ViewModel.SelectedBooks.Remove(book); } foreach (Book book in e.AddedItems) { ViewModel.SelectedBooks.Add(book); } } } public class BookListViewModel : ViewModel&lt;IBookListView&gt; { private readonly IEnumerable&lt;Book&gt; books; private readonly ObservableCollection&lt;Book&gt; selectedBooks; private Book selectedBook; private ICommand addNewCommand; private ICommand removeCommand; public BookListViewModel(IBookListView view, IEnumerable&lt;Book&gt; books) : base(view) { if (books == null) { throw new ArgumentNullException("books"); } this.books = books; this.selectedBooks = new ObservableCollection&lt;Book&gt;(); } public IEnumerable&lt;Book&gt; Books { get { return books; } } public ObservableCollection&lt;Book&gt; SelectedBooks { get { return selectedBooks; } } public Book SelectedBook { get { return selectedBook; } set { if (selectedBook != value) { selectedBook = value; RaisePropertyChanged("SelectedBook"); } } } public ICommand AddNewCommand { get { return addNewCommand; } set { if (addNewCommand != value) { addNewCommand = value; RaisePropertyChanged("AddNewCommand"); } } } public ICommand RemoveCommand { get { return removeCommand; } set { if (removeCommand != value) { removeCommand = value; RaisePropertyChanged("RemoveCommand"); } } } } </code></pre> <p><strong>BookController</strong>: Here the books are fetched from Entity Framework/database</p> <pre><code>public void Initialize() { bookViewModel.LendToCommand = lendToCommand; bookViewModel.PropertyChanged += BookViewModelPropertyChanged; IBookListView bookListView = container.GetExportedValue&lt;IBookListView&gt;(); bookListViewModel = new BookListViewModel(bookListView, entityService.Books); bookListViewModel.AddNewCommand = addNewCommand; bookListViewModel.RemoveCommand = removeCommand; bookListViewModel.PropertyChanged += BookListViewModelPropertyChanged; shellViewModel.BookListView = bookListViewModel.View; shellViewModel.BookView = bookViewModel.View; bookListViewModel.SelectedBook = bookListViewModel.Books.FirstOrDefault(); } </code></pre> <p>and exactly those books are passed bookListViewModel = new BookListViewModel(bookListView, entityService.Books); to the BookListViewModel which is set as DataContext of the BookListView.xaml binding to books.</p> <p>I was shocked!!! Am I right that they directly bind to the models properties?</p>
    singulars
    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