Click here to Skip to main content
14,331,160 members

Silverlight / WPF

 
QuestionStyling a Drag and Drop Items behavior in a WPF ListView Pin
Kenneth Haugland13-Jul-16 5:43
professionalKenneth Haugland13-Jul-16 5:43 
QuestionShort way defining a property with the NotifyPropertyChanged() call Pin
Mc_Topaz9-Jul-16 9:26
memberMc_Topaz9-Jul-16 9:26 
AnswerRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Mycroft Holmes9-Jul-16 11:35
memberMycroft Holmes9-Jul-16 11:35 
AnswerRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Mc_Topaz9-Jul-16 11:49
memberMc_Topaz9-Jul-16 11:49 
AnswerRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Super Lloyd10-Jul-16 14:31
memberSuper Lloyd10-Jul-16 14:31 
AnswerRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Pete O'Hanlon10-Jul-16 21:23
protectorPete O'Hanlon10-Jul-16 21:23 
AnswerRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Gerry Schmitz11-Jul-16 6:04
mveGerry Schmitz11-Jul-16 6:04 
AnswerRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Kenneth Haugland13-Jul-16 4:12
professionalKenneth Haugland13-Jul-16 4:12 
I usually do this (took the code from somwhere but I cant remember the referance):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;

    /// <summary>
    ///     Implementation of <see cref="INotifyPropertyChanged" />  and Frameworkelement to simplify base drawing classes.
    /// </summary>
    public abstract class NotifierBase : INotifyPropertyChanged
    {
        /// <summary>
        ///     Multicast event for property change notifications.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        ///     Checks if a property already matches a desired value.  Sets the property and
        ///     notifies listeners only when necessary.
        /// </summary>
        /// <typeparam name="T">Type of the property.</typeparam>
        /// <param name="storage">Reference to a property with both getter and setter.</param>
        /// <param name="value">Desired value for the property.</param>
        /// <param name="propertyName">
        ///     Name of the property used to notify listeners.  This
        ///     value is optional and can be provided automatically when invoked from compilers that
        ///     support CallerMemberName.
        /// </param>
        /// <returns>
        ///     True if the value was changed, false if the existing value matched the
        ///     desired value.
        /// </returns>
        protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
        {

            if (Equals(storage, value))
            {
                return false;
            }

            storage = value;
            this.OnPropertyChanged(propertyName);
            return true;
        }

        /// <summary>
        ///     Notifies listeners that a property value has changed.
        /// </summary>
        /// <param name="propertyName">
        ///     Name of the property used to notify listeners.  This
        ///     value is optional and can be provided automatically when invoked from compilers
        ///     that support <see cref="CallerMemberNameAttribute" />.
        /// </param>
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

Then I simply call it like this:
private string m_Name ="";
public string Name
{
    get { return m_Name; }
    set
    {
        SetProperty(ref m_Name, value);
    }
}

I just have a custom snippet to deal with the proeprty coding.
GeneralRe: Short way defining a property with the NotifyPropertyChanged() call Pin
Mycroft Holmes13-Jul-16 12:54
memberMycroft Holmes13-Jul-16 12:54 
QuestionAdd column sorting to a WPF grid Pin
holdorf7-Jul-16 7:11
memberholdorf7-Jul-16 7:11 
SuggestionRe: Add column sorting to a WPF grid Pin
Matt T Heffron7-Jul-16 7:39
professionalMatt T Heffron7-Jul-16 7:39 
GeneralRe: Add column sorting to a WPF grid Pin
holdorf7-Jul-16 8:11
memberholdorf7-Jul-16 8:11 
AnswerRe: Add column sorting to a WPF grid Pin
Gerry Schmitz8-Jul-16 6:52
mveGerry Schmitz8-Jul-16 6:52 
QuestionSingle Instance WPF App - Pass Params From Second Instance To First Instance Pin
Kevin Marois30-Jun-16 8:46
professionalKevin Marois30-Jun-16 8:46 
QuestionWPF empty tabbed dashboard example code Pin
holdorf28-Jun-16 12:07
memberholdorf28-Jun-16 12:07 
AnswerRe: WPF empty tabbed dashboard example code Pin
Pete O'Hanlon28-Jun-16 20:53
protectorPete O'Hanlon28-Jun-16 20:53 
SuggestionRe: WPF empty tabbed dashboard example code Pin
Richard MacCutchan28-Jun-16 21:09
protectorRichard MacCutchan28-Jun-16 21:09 
AnswerRe: WPF empty tabbed dashboard example code Pin
Gerry Schmitz1-Jul-16 5:47
mveGerry Schmitz1-Jul-16 5:47 
GeneralRe: WPF empty tabbed dashboard example code Pin
holdorf6-Jul-16 10:11
memberholdorf6-Jul-16 10:11 
QuestionRaisePropertyChanged is not being called Pin
Kevin Marois27-Jun-16 10:41
professionalKevin Marois27-Jun-16 10:41 
AnswerRe: RaisePropertyChanged is not being called Pin
Mycroft Holmes27-Jun-16 14:27
memberMycroft Holmes27-Jun-16 14:27 
AnswerRe: RaisePropertyChanged is not being called Pin
Bernhard Hiller27-Jun-16 21:50
memberBernhard Hiller27-Jun-16 21:50 
AnswerRe: RaisePropertyChanged is not being called Pin
Jacob Himes28-Jun-16 22:28
professionalJacob Himes28-Jun-16 22:28 
QuestionWPF Diagram Of Logical & Visual Trees Pin
Kevin Marois23-Jun-16 13:56
professionalKevin Marois23-Jun-16 13:56 
AnswerRe: WPF Diagram Of Logical & Visual Trees Pin
Gerry Schmitz24-Jun-16 3:53
mveGerry Schmitz24-Jun-16 3:53 

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.