Click or drag to resize

PageConfigurationUIButtonCopy_Click Method

Button event: triggers of event Copy or override this.

Namespace:  SOWIWin.Helper
Assembly:  SOWIWin.Helper (in SOWIWin.Helper.dll) Version: 19.1.23.1 (19.1.23.622)
Syntax
protected virtual void ButtonCopy_Click(
	Object sender,
	RoutedEventArgs e
)

Parameters

sender
Type: SystemObject
Button object
e
Type: System.WindowsRoutedEventArgs
This object to pass on event Copy
Examples
This example override this and copies and inserts selected configuration
/// <summary>
/// Button event: copies and inserts selected configuration
/// </summary>
/// <param name="sender">Button object</param>
/// <param name="e"></param>
protected override void ButtonCopy_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var lItem = this.DataGridConfiguration.SelectedItem;
        var lItemCopy = (DataItemClass)Copy(lItem);
        var lItemCopyXML = (SIC.Setting.ISettingXML)lItemCopy;
        lItemCopyXML.Name = Guid.NewGuid().ToString();
        lItemCopy = (DataItemClass)lItemCopyXML;
        this.Configuration.Insert(lItemCopy);
        this.DataGridConfiguration.DataContext = this.Configuration.GetAll();
    }
    catch (Exception ex)
    {
        SOWIWin.Helper.Message.Show(ex.Message.ToString());
    }
}
Method example for copies for a object
/// <summary>
/// Copies a object
/// </summary>
/// <param name="pObject">Object to copy</param>
/// <returns>Copied object</returns>
private object Copy(object pObject)
{
    Type pType = pObject.GetType();
    PropertyInfo[] pProperties = pType.GetProperties();
    Object lMember = pType.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, pObject, null);
    foreach (PropertyInfo lProperty in pProperties)
    {
        if (lProperty.CanWrite)
        {
            try
            {
                lProperty.SetValue(lMember, lProperty.GetValue(pObject, null), null);
            }
            catch
            {
                // exception doesn't handling!
            }
        }
    }
    return lMember;
}
See Also