Click here to Skip to main content
15,884,176 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Starter MVVM Framework Recommendation Pin
Stein Borge19-Jun-14 1:58
Stein Borge19-Jun-14 1:58 
GeneralRe: Starter MVVM Framework Recommendation Pin
Geert van Horrik20-Jun-14 8:40
Geert van Horrik20-Jun-14 8:40 
GeneralRe: Starter MVVM Framework Recommendation Pin
_Maxxx_6-Jul-14 19:16
professional_Maxxx_6-Jul-14 19:16 
QuestionBind to static property which change in runtime Pin
Mc_Topaz16-Jun-14 23:23
Mc_Topaz16-Jun-14 23:23 
AnswerRe: Bind to static property which change in runtime Pin
Pete O'Hanlon16-Jun-14 23:55
mvePete O'Hanlon16-Jun-14 23:55 
SuggestionRe: Bind to static property which change in runtime Pin
Richard Deeming17-Jun-14 1:43
mveRichard Deeming17-Jun-14 1:43 
GeneralRe: Bind to static property which change in runtime Pin
Pete O'Hanlon17-Jun-14 1:53
mvePete O'Hanlon17-Jun-14 1:53 
AnswerRe: Bind to static property which change in runtime Pin
Richard Deeming17-Jun-14 1:50
mveRichard Deeming17-Jun-14 1:50 
Pete's answer is almost there, except you can't raise a non-static event from the setter of a static property.

Pete Brown has the solution:

There are two ways to notify the binding system of property changes, both of which follow the same pattern as their instance-based relatives. The first is to create a static event named <propertyName>Changed. The second approach is to create a single event which is the static version of the INPC PropertyChanged event named StaticPropertyChanged.


So in your code, you would either have:
C#
public static event EventHandler AgeChanged;

static int age = 10;
public static int Age
{
    get { return age; }
    private set
    {
        age = value;
        
        var handler = AgeChanged;
        if (handler != null) handler(null, EventArgs.Empty);
    }
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    Age = (Age == 10) ? 11 : 10;
}


or:
C#
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

private static void NotifyStaticPropertyChanged(string propertyName)
{
    var handler = StaticPropertyChanged;
    if (handler != null) handler(null, new PropertyChangedEventArgs(propertyName));
}

static int age = 10;
public static int Age
{
    get { return age; }
    private set
    {
        age = value;
        NotifyStaticPropertyChanged("Age");
    }
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    Age = (Age == 10) ? 11 : 10;
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionRichTextBox in WPF really slow... Why? Pin
LLLLGGGG13-Jun-14 9:09
LLLLGGGG13-Jun-14 9:09 
AnswerRe: RichTextBox in WPF really slow... Why? Pin
Pete O'Hanlon15-Jun-14 20:09
mvePete O'Hanlon15-Jun-14 20:09 
GeneralRe: RichTextBox in WPF really slow... Why? Pin
LLLLGGGG15-Jun-14 23:18
LLLLGGGG15-Jun-14 23:18 
GeneralRe: RichTextBox in WPF really slow... Why? Pin
Pete O'Hanlon16-Jun-14 0:18
mvePete O'Hanlon16-Jun-14 0:18 
QuestionWPF ListBox Data Template Problem Pin
Kevin Marois11-Jun-14 9:08
professionalKevin Marois11-Jun-14 9:08 
AnswerRe: WPF ListBox Data Template Problem Pin
simbos11-Jun-14 10:17
simbos11-Jun-14 10:17 
QuestionWPF ListBox Losing Focus Pin
Kevin Marois9-Jun-14 13:44
professionalKevin Marois9-Jun-14 13:44 
QuestionWPF ListBox in DataTemplate ListBox - Binding Question Pin
Kevin Marois9-Jun-14 9:44
professionalKevin Marois9-Jun-14 9:44 
QuestionWPF - Hierarchy of Expanders & ListBoxes Pin
Kevin Marois9-Jun-14 7:59
professionalKevin Marois9-Jun-14 7:59 
QuestionWPF / MVVM - Displaying tabcontent only in my system and not displaying other developers/user screen Pin
Member 80814488-Jun-14 4:02
Member 80814488-Jun-14 4:02 
AnswerRe: WPF / MVVM - Displaying tabcontent only in my system and not displaying other developers/user screen Pin
Wes Aday8-Jun-14 5:28
professionalWes Aday8-Jun-14 5:28 
Questionform loads on build Pin
bryce3-Jun-14 15:17
bryce3-Jun-14 15:17 
AnswerRe: form loads on build Pin
Pete O'Hanlon4-Jun-14 5:51
mvePete O'Hanlon4-Jun-14 5:51 
GeneralRe: form loads on build Pin
Kevin Marois9-Jun-14 8:39
professionalKevin Marois9-Jun-14 8:39 
QuestionWPF ListBox - Select ListItem From DataTemplate Pin
Kevin Marois2-Jun-14 13:02
professionalKevin Marois2-Jun-14 13:02 
QuestionDetection of physical keyboard on Windows 7 in a desktop WPF application Pin
Jenny D30-May-14 12:04
Jenny D30-May-14 12:04 
AnswerRe: Detection of physical keyboard on Windows 7 in a desktop WPF application Pin
Bernhard Hiller2-Jun-14 0:20
Bernhard Hiller2-Jun-14 0:20 

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.