Click here to Skip to main content
15,895,656 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Custom Control & Binding woe Pin
Super Lloyd4-May-11 15:59
Super Lloyd4-May-11 15:59 
QuestionBest Way To Do This Pin
Kevin Marois4-May-11 12:57
professionalKevin Marois4-May-11 12:57 
AnswerRe: Best Way To Do This Pin
Pete O'Hanlon4-May-11 13:17
mvePete O'Hanlon4-May-11 13:17 
GeneralRe: Best Way To Do This Pin
Kevin Marois4-May-11 13:21
professionalKevin Marois4-May-11 13:21 
GeneralRe: Best Way To Do This Pin
SledgeHammer014-May-11 14:19
SledgeHammer014-May-11 14:19 
AnswerRe: Best Way To Do This Pin
Renat Khabibulin4-May-11 16:55
Renat Khabibulin4-May-11 16:55 
AnswerRe: Best Way To Do This Pin
RichardGrimmer20-May-11 3:58
RichardGrimmer20-May-11 3:58 
QuestionWCF RIA / MVVM Question Pin
eddieangel4-May-11 11:33
eddieangel4-May-11 11:33 
More of a request for clarification really. I am working on a Silverlight application using WCF RIA and MVVM and I am having a tough time understanding some of the deep abstraction I am seeing in examples. I am looking at the MS Bookshelf example and I really am lost to understand why there are so freaking many moving parts. See the following pieces:

Interface <abridged>:

public interface IBookDataService
{
    event EventHandler<HasChangesEventArgs> NotifyHasChanges;
    void Save(Action<SubmitOperation> submitCallback, object state);
    void GetBooksByCategory(
        Action<ObservableCollection<Book>> getBooksCallback,
        int categoryID,
        int pageSize);
    void GetCategories(Action<ObservableCollection<Category>> getCategoriesCallback);
}


Class implementation of interface:
public class BookDataService : IBookDataService
   {
       private LoadOperation<Book> _booksLoadOperation;
       private LoadOperation<Category> _categoriesLoadOperation;

       private Action<ObservableCollection<Book>> _getBooksCallback;
       private Action<ObservableCollection<Category>> _getCategoriesCallback;

       private int _pageIndex = 0;
       private BookClubContext Context { get; set; }
       public event EventHandler<HasChangesEventArgs> NotifyHasChanges;

       public BookDataService()
       {
           Context = new BookClubContext();
           Context.PropertyChanged += ContextPropertyChanged;
       }


       private void ContextPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
       {
           if (NotifyHasChanges != null)
           {
               NotifyHasChanges(this, new HasChangesEventArgs(){HasChanges  = Context.HasChanges});
           }
       }

       public void Save(Action<SubmitOperation> submitCallback, object state)
       {
           if (Context.HasChanges)
           {
               Context.SubmitChanges(submitCallback, state);
           }
       }

       public void GetBooksByCategory(
           Action<ObservableCollection<Book>> getBooksCallback,
           int categoryID,
           int pageSize)
       {
           ClearBooks();
           var query = Context.GetBooksByCategoryQuery(categoryID).Take(pageSize);
           RunBooksQuery(query, getBooksCallback);
       }

       public void GetBooksByTitle(Action<ObservableCollection<Book>> getBooksCallback, int categoryID, string titleFilter)
       {
           ClearBooks();
           var query = Context.GetBooksByCategoryQuery(categoryID)
               .Where(b => b.Title.Contains(titleFilter));
           RunBooksQuery(query, getBooksCallback);
       }

       private void ClearBooks()
       {
           _pageIndex = 0;
           Context.Books.Clear();
       }

       private void RunBooksQuery(EntityQuery<Book> query, Action<ObservableCollection<Book>> getBooksCallback)
       {
           _getBooksCallback = getBooksCallback;
           _booksLoadOperation = Context.Load<Book>(query);
           _booksLoadOperation.Completed += OnLoadBooksCompleted;
       }

       private void OnLoadBooksCompleted(object sender, EventArgs e)
       {
           _booksLoadOperation.Completed -= OnLoadBooksCompleted;
           var books = new EntityList<Book>(Context.Books, _booksLoadOperation.Entities);
           _getBooksCallback(books);
       }

       public void GetCategories(Action<ObservableCollection<Category>> getCategoriesCallback)
       {
           _getCategoriesCallback = getCategoriesCallback;
           Context.Categories.Clear();
           _categoriesLoadOperation = Context.Load<Category>(Context.GetCategoriesQuery());
           _categoriesLoadOperation.Completed += OnLoadCategoriesCompleted;
       }

       private void OnLoadCategoriesCompleted(object sender, EventArgs e)
       {
           _categoriesLoadOperation.Completed -= OnLoadCategoriesCompleted;
           var categories = new EntityList<Category>(Context.Categories, _categoriesLoadOperation.Entities);
           _getCategoriesCallback(categories);
       }
   }

And the viewmodel too:
 public void LoadBooksByCategory()
 {
     //Books.Clear();
     Books = null;
     if (SelectedCategory != null)
         BookDataService.GetBooksByCategory(GetBooksCallback, SelectedCategory.CategoryID, _pageSize);
 }

private void GetBooksCallback(ObservableCollection<Book> books)
 {
     if (books != null)
     {
         if (Books == null)
         {
             Books = books;
         }
         else
         {
             foreach (var book in books)
             {
                 Books.Add(book);
             }
         }

         if (Books.Count > 0)
         {
             SelectedBook = Books[0];
         }

     }
 }


And there is the web side components as well. The thing is, it is a lot of code and I am trying to figure out why there is so much of it? Can someone just give me a quick breakdown of why there are so many callbacks? I have never been crystal clear on callbacks and delegates to begin with, so this is just a nightmarish mess.

Cheers, --EA
AnswerRe: WCF RIA / MVVM Question Pin
Pete O'Hanlon4-May-11 12:25
mvePete O'Hanlon4-May-11 12:25 
QuestionHow do I databind a ListView to a property in child collection in WPF? Pin
B2C4-May-11 3:01
B2C4-May-11 3:01 
AnswerRe: How do I databind a ListView to a property in child collection in WPF? Pin
RichardGrimmer4-May-11 4:33
RichardGrimmer4-May-11 4:33 
GeneralRe: How do I databind a ListView to a property in child collection in WPF? Pin
B2C4-May-11 5:15
B2C4-May-11 5:15 
GeneralRe: How do I databind a ListView to a property in child collection in WPF? Pin
SledgeHammer014-May-11 7:00
SledgeHammer014-May-11 7:00 
GeneralRe: How do I databind a ListView to a property in child collection in WPF? Pin
AspDotNetDev4-May-11 7:59
protectorAspDotNetDev4-May-11 7:59 
AnswerRe: How do I databind a ListView to a property in child collection in WPF? Pin
Ian Shlasko4-May-11 5:40
Ian Shlasko4-May-11 5:40 
QuestionPrintable Area's Size - SL Printing API Pin
jadughar4-May-11 0:38
jadughar4-May-11 0:38 
AnswerRe: PageVisual's Size - SL Printing API Pin
Pete O'Hanlon4-May-11 2:18
mvePete O'Hanlon4-May-11 2:18 
GeneralRe: PageVisual's Size - SL Printing API Pin
jadughar4-May-11 4:24
jadughar4-May-11 4:24 
QuestionMVVM Pin
arkiboys3-May-11 22:50
arkiboys3-May-11 22:50 
AnswerRe: MVVM Pin
Dave Kerr3-May-11 23:09
mentorDave Kerr3-May-11 23:09 
GeneralRe: MVVM Pin
arkiboys3-May-11 23:19
arkiboys3-May-11 23:19 
QuestionSilverlight Compatibility with existing C#2.0 libraries Pin
insanechingi3-May-11 22:14
insanechingi3-May-11 22:14 
AnswerRe: Silverlight Compatibility with existing C#2.0 libraries Pin
Pete O'Hanlon3-May-11 23:14
mvePete O'Hanlon3-May-11 23:14 
QuestionSilverlight best Printing solution ??? Pin
jadughar2-May-11 4:08
jadughar2-May-11 4:08 
AnswerRe: Silverlight best Printing solution ??? Pin
Pete O'Hanlon2-May-11 9:40
mvePete O'Hanlon2-May-11 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.