Click here to Skip to main content
15,886,873 members
Home / Discussions / WPF
   

WPF

 
QuestionDraw a rectangular box Pin
Subin Mavunkal1-Jul-14 23:24
Subin Mavunkal1-Jul-14 23:24 
AnswerRe: Draw a rectangular box Pin
Matt T Heffron2-Jul-14 13:53
professionalMatt T Heffron2-Jul-14 13:53 
QuestionXAML Pin
Member 97193591-Jul-14 22:21
Member 97193591-Jul-14 22:21 
AnswerRe: XAML Pin
Pete O'Hanlon1-Jul-14 22:55
mvePete O'Hanlon1-Jul-14 22:55 
QuestionWPF Expander Problem Pin
Kevin Marois1-Jul-14 13:49
professionalKevin Marois1-Jul-14 13:49 
AnswerRe: WPF Expander Problem Pin
Pete O'Hanlon1-Jul-14 19:11
mvePete O'Hanlon1-Jul-14 19:11 
QuestionWPF - PRism Framework Pin
Muhammed Nigil29-Jun-14 23:36
professionalMuhammed Nigil29-Jun-14 23:36 
AnswerRe: WPF - PRism Framework Pin
Pete O'Hanlon30-Jun-14 0:17
mvePete O'Hanlon30-Jun-14 0:17 
The only really remarkable thing about an ObservableCollection is that it implements INotifyCollectionChanged. This interface contains a CollectionChanged event when the number of items in the collection is changed somehow. When WPF sees that an item it is binding to implements this interface, it knows that it can listen to this event.

Okay, so that's the ObservableCollection. Why did I bring it up? Well, that's because the collection changing is taken care of for you by a custom collection. Property changes, on the other hand, aren't handled automatically for you. When you think about it, you can see why this is desirable. Would you really want WPF to be listening for changes on every property you've bound it to, even if those properties are straightforward primitives. Implementing automatic change binding on these would put a tremendous strain on your application because you would potentially be wiring up many items that you don't want to. So, how do you do property change notification? Well, in just the same way you have INotifyCollectionChanged, there's a property change interface that WPF understands called INotifyPropertyChanged. This interface has a PropertyChanged event that you raise to tell WPF that a particular item has changed (by passing the name of the item that changed, or an empty string if you want WPF to refresh all properties).

Now, if you've heard of MVVM, you're probably aware of a concept called a ViewModel. The ViewModel is intended to isolate the View from the Model. It's a common implementation pattern that has a BaseViewModel class that handles the INotifyPropertyChanged (often abbreviated to INPC). So, the base VM would look something like this:
C#
public abstract class BaseViewModel : INotifyPropertyChanged
{
  protected void NotifyOfChange(string property)
  {
    PropertyChangedEventHandler handler = PropertyChanged;
    if (handler == null) return;
    handler(this, new PropertyChangedEventArgs(property));
  }

  public event PropertyChangedEventHandler PropertyChanged;
}
So, your derived VM would possibly look something like this:
C#
public class MyViewModel : BaseViewModel
{
  private int _onlineCount;

  public int OnlineCount
  {
    get { return _onlineCount; }
    set
    {
      if (_onlineCount == value) return;
      _onlnieCount = value;
      NotifyOfChange("OnlineCount");
    }
  }
}

GeneralRe: WPF - PRism Framework Pin
Muhammed Nigil30-Jun-14 1:00
professionalMuhammed Nigil30-Jun-14 1:00 
GeneralRe: WPF - PRism Framework Pin
Pete O'Hanlon30-Jun-14 3:03
mvePete O'Hanlon30-Jun-14 3:03 
GeneralRe: WPF - PRism Framework Pin
Muhammed Nigil30-Jun-14 18:56
professionalMuhammed Nigil30-Jun-14 18:56 
GeneralRe: WPF - PRism Framework Pin
Muhammed Nigil30-Jun-14 19:26
professionalMuhammed Nigil30-Jun-14 19:26 
QuestionHow to display from nested usercontrol another usercontrol class on button click event? Pin
LAPEC29-Jun-14 7:12
LAPEC29-Jun-14 7:12 
QuestionHow to Display .aspx page in SilverlightWeb Application Pin
RavitejaPammi28-Jun-14 5:22
RavitejaPammi28-Jun-14 5:22 
Questionsilverlight Pin
Member 1087962427-Jun-14 19:40
Member 1087962427-Jun-14 19:40 
AnswerRe: silverlight Pin
Pete O'Hanlon29-Jun-14 6:51
mvePete O'Hanlon29-Jun-14 6:51 
GeneralRe: silverlight Pin
Jammer30-Jun-14 23:32
Jammer30-Jun-14 23:32 
GeneralRe: silverlight Pin
Pete O'Hanlon30-Jun-14 23:59
mvePete O'Hanlon30-Jun-14 23:59 
GeneralRe: silverlight Pin
thatraja30-Jun-14 23:52
professionalthatraja30-Jun-14 23:52 
GeneralRe: silverlight Pin
Pete O'Hanlon1-Jul-14 0:10
mvePete O'Hanlon1-Jul-14 0:10 
QuestionRepost from C# forum WPF app Pin
Wesley2026-Jun-14 23:26
Wesley2026-Jun-14 23:26 
AnswerRe: Repost from C# forum WPF app Pin
Mycroft Holmes29-Jun-14 4:55
professionalMycroft Holmes29-Jun-14 4:55 
QuestionWPF Combo Box SelectedValue = null issue Pin
Mhister Pamakwas25-Jun-14 11:54
Mhister Pamakwas25-Jun-14 11:54 
AnswerRe: WPF Combo Box SelectedValue = null issue Pin
Mycroft Holmes29-Jun-14 5:01
professionalMycroft Holmes29-Jun-14 5:01 
QuestionWPF RichTextBox Document Bind using Binding property Pin
moorthy00724-Jun-14 0:29
moorthy00724-Jun-14 0:29 

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.