B
B
bagos2015-08-13 17:54:45
WPF
bagos, 2015-08-13 17:54:45

The setter of the zabindin property does not work, what could be the reason?

There is a class with N properties, all of them are bound with the necessary controls on the form (WPF).
Next, the structure is created

public struct MyStruct
{
  public int Age {get;set;}
  public string Name {get;set;}
}

private MyStruct _mm;
public MyStruct MM
{
get {return _mm;}
}
set 
{
_mm = value; 
OnPropertyChanged("MM");
}

To controls bind = MM.Name and MM.Age
The data is displayed. But when you try to change them in the control, they reset to the old values. When changing values ​​in a field, the debugger ignores the setter. Maybe the problem is that he created an instance of the structure?
When loaded, it creates
ММ = new MyStruct 
{
name = "123",
 age = 456
};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rainbird, 2015-08-13
@bagos

Of course, the whole point is that it is a structure. And structures in c# are value types.

A
Alexander Movchan, 2015-08-13
@Alexander1705

You placed a set block outside of a property block.

public MyStruct MM
{
    get {return _mm;}
}
set 
{
    _mm = value; 
    OnPropertyChanged("MM");
}

This is how it works:
public MyStruct MM
{
    get {return _mm;}

    set 
    {
        _mm = value; 
        OnPropertyChanged("MM");
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question