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

WPF

 
AnswerRe: combining a textblock and textblock into one control Pin
Mycroft Holmes23-Mar-12 21:58
professionalMycroft Holmes23-Mar-12 21:58 
GeneralRe: combining a textblock and textblock into one control Pin
Abhinav S24-Mar-12 0:10
Abhinav S24-Mar-12 0:10 
GeneralRe: combining a textblock and textblock into one control Pin
Sutton Mehaffey24-Mar-12 5:37
Sutton Mehaffey24-Mar-12 5:37 
GeneralRe: combining a textblock and textblock into one control Pin
Mycroft Holmes24-Mar-12 13:23
professionalMycroft Holmes24-Mar-12 13:23 
GeneralRe: combining a textblock and textblock into one control Pin
Sutton Mehaffey24-Mar-12 13:49
Sutton Mehaffey24-Mar-12 13:49 
GeneralRe: combining a textblock and textblock into one control Pin
Mycroft Holmes24-Mar-12 16:05
professionalMycroft Holmes24-Mar-12 16:05 
GeneralRe: combining a textblock and textblock into one control Pin
Sutton Mehaffey26-Mar-12 14:27
Sutton Mehaffey26-Mar-12 14:27 
GeneralRe: combining a textblock and textblock into one control Pin
Mycroft Holmes26-Mar-12 15:24
professionalMycroft Holmes26-Mar-12 15:24 
Not sure how you are set up but you are not implementing OnPropertyChange on your model public class ZoneDescEntry and your collections are generic rather than ObservableCollection this indicates that there is no notification about any changes to your data.

I use a BaseModel class that implements INotifyPropertyChanged and the Model implements IEditableObject this give me control of the editing process and I get notification of the data changes.

My BaseModel
HTML
public abstract class BaseModel : INotifyPropertyChanged
{

    public BaseModel() { }
    #region Events
    /// <summary>
    /// PropertyChanged event.
    /// </summary>
    public event PropertyChangedEventHandler PropertyChanged;
    #endregion


    private bool _IsDataChanged;
    public bool IsDataChanged
    {
        get
        { return _IsDataChanged; }
        set
        {
            if (_IsDataChanged == value)
            {
                return;
            }
            var oldValue = _IsDataChanged;
            _IsDataChanged = value;
            OnPropertyChanged("IsDataChanged");
        }
    }

    public void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = this.PropertyChanged;

        if (handler != null)
        {
            if (propertyName != "IsDataChanged")
            { IsDataChanged = true; }

            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    /// <summary>
    /// get a shallow copy of object of type T.
    /// objects with other object properties has not been tested.
    /// </summary>
    public static T ShallowCopy<T>(object objToCopy) where T : class, new()
    {
        if (objToCopy == null)
        { return null; }

        Type objType = typeof(T);
        object oValue;
        PropertyInfo oPropNew;
        T objNew = Activator.CreateInstance<T>(); //hence the new() contsraint
        //Debug.WriteLine(objType.Name + " = new " + objType.Name + "();");
        PropertyInfo[] oPInfos = objType.GetProperties();

        foreach (PropertyInfo oPInfo in oPInfos)
        {
            //may error if no mat
            oPropNew = objType.GetProperty(oPInfo.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
            oValue = oPInfo.GetValue(objToCopy, null);

            oPropNew.SetValue(objNew, oValue, null);
        }
        return objNew;
    }

    public static T ReverseCopy<T>(object EditableObject, object SelectedObject) where T : class, new()
    {
        if (EditableObject == null)
        { return null; }
        Type objType = typeof(T);
        object oValue;
        //Debug.WriteLine(objType.Name + " = new " + objType.Name + "();");
        PropertyInfo[] oPInfos = objType.GetProperties();
        foreach (PropertyInfo oPInfo in oPInfos)
        {
            //may error if no match
            PropertyInfo oPropNew = objType.GetProperty(oPInfo.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
            oValue = oPInfo.GetValue(EditableObject, null);
            oPropNew.SetValue(SelectedObject, oValue, null);
        }
        return (T)SelectedObject;
    }
}


The Model class
HTML
public class ZoneDescEntryDB : BaseModel, IEditableObject
{

    private string _ZoneNum;
    public string ZoneNum
    {
        get
        { return _ZoneNum; }
        set
        {
            if (_ZoneNum == value)
            {
                return;
            }
            var oldValue = _ZoneNum;
            _ZoneNum = value;
            base.OnPropertyChanged("ZoneNum");
        }
    }

    private string _ZoneDesc;
    public string ZoneDesc
    {
        get
        { return _ZoneDesc; }
        set
        {
            if (_ZoneDesc == value)
            {
                return;
            }
            var oldValue = _ZoneDesc;
            _ZoneDesc = value;
            base.OnPropertyChanged("ZoneDesc");
        }
    }

    #region                                             Edit methods
    private ZoneDescEntryDB Backup { get; set; }
    public void BeginEdit()
    {
        Backup = ShallowCopy<ZoneDescEntryDB>(this);
        IsDataChanged = false;
    }

    public void EndEdit()
    {
        Backup = null;
        IsDataChanged = false;
    }

    public void CancelEdit()
    {
        ReverseCopy<ZoneDescEntryDB>(Backup, this); Backup = null;
        IsDataChanged = false;
    }
    #endregion Edit methods

}

Never underestimate the power of human stupidity
RAH

GeneralRe: combining a textblock and textblock into one control Pin
Sutton Mehaffey26-Mar-12 16:01
Sutton Mehaffey26-Mar-12 16:01 
AnswerRe: combining a textblock and textblock into one control Pin
Abhinav S24-Mar-12 0:25
Abhinav S24-Mar-12 0:25 
QuestionPrism and Login Page problem Pin
gio_ab23-Mar-12 3:25
gio_ab23-Mar-12 3:25 
AnswerRe: Prism and Login Page problem Pin
Abhinav S23-Mar-12 17:27
Abhinav S23-Mar-12 17:27 
QuestionWPF C1Flexgrid Pin
Greeshma M J22-Mar-12 20:24
Greeshma M J22-Mar-12 20:24 
AnswerRe: WPF C1Flexgrid Pin
RugbyLeague23-Mar-12 6:51
RugbyLeague23-Mar-12 6:51 
GeneralRe: WPF C1Flexgrid Pin
Greeshma M J25-Mar-12 18:26
Greeshma M J25-Mar-12 18:26 
QuestionUpload images to Server Pin
sudheesh kumar s22-Mar-12 2:51
sudheesh kumar s22-Mar-12 2:51 
QuestionExpander Styling Question Pin
Kevin Marois20-Mar-12 14:13
professionalKevin Marois20-Mar-12 14:13 
AnswerRe: Expander Styling Question Pin
Varsha Ramnani21-Mar-12 0:49
professionalVarsha Ramnani21-Mar-12 0:49 
GeneralRe: Expander Styling Question Pin
Abhinav S21-Mar-12 4:14
Abhinav S21-Mar-12 4:14 
GeneralRe: Expander Styling Question Pin
Kevin Marois21-Mar-12 7:25
professionalKevin Marois21-Mar-12 7:25 
QuestionWPF Path Pin
Kevin Marois20-Mar-12 8:44
professionalKevin Marois20-Mar-12 8:44 
AnswerRe: WPF Path Pin
Pete O'Hanlon20-Mar-12 11:42
mvePete O'Hanlon20-Mar-12 11:42 
GeneralRe: WPF Path Pin
Kevin Marois20-Mar-12 11:44
professionalKevin Marois20-Mar-12 11:44 
GeneralRe: WPF Path Pin
Kevin Marois20-Mar-12 11:56
professionalKevin Marois20-Mar-12 11:56 
GeneralRe: WPF Path Pin
Pete O'Hanlon20-Mar-12 12:23
mvePete O'Hanlon20-Mar-12 12:23 

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.