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

C#

 
AnswerRe: how can we add a reference in c#.net project programmatically?? Pin
Dave Kreskowiak27-Oct-12 3:37
mveDave Kreskowiak27-Oct-12 3:37 
AnswerRe: how can we add a reference in c#.net project programmatically?? Pin
Eddy Vluggen27-Oct-12 4:24
professionalEddy Vluggen27-Oct-12 4:24 
AnswerRe: how can we add a reference in c#.net project programmatically?? Pin
Clifford Nelson29-Oct-12 13:54
Clifford Nelson29-Oct-12 13:54 
QuestionApp Without Installation Pin
C-P-User-326-Oct-12 10:33
C-P-User-326-Oct-12 10:33 
AnswerRe: App Without Installation Pin
Ravi Bhavnani26-Oct-12 10:41
professionalRavi Bhavnani26-Oct-12 10:41 
AnswerRe: App Without Installation Pin
Clifford Nelson26-Oct-12 12:11
Clifford Nelson26-Oct-12 12:11 
AnswerRe: App Without Installation Pin
Eddy Vluggen27-Oct-12 4:28
professionalEddy Vluggen27-Oct-12 4:28 
QuestionBest way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
Praveen Raghuvanshi26-Oct-12 9:40
professionalPraveen Raghuvanshi26-Oct-12 9:40 
I have been working on a WPF application and looking for the best way to implement the 'Ok' and 'Cancel' button click functionality in the modal dialog boxes.
The question has two parts:

Part -1:
Currently, I am doing it by creating a copy/clone of the actual object whenever we load the dialog. Later, I perform all the operations on the cloned object in the Modal dialog. If user press 'Ok', i'll assign all the values in the clone object to the actual object. If user press 'Cancel, i'll discard the cloned object and set it to null.

For E.g:
Suppose, I have a class Person
<pre lang="c#">
Class Person
{
public string FirstName {get; set;}
public string LastName {get; set;}
}</pre>

I have another class which holds the list of 'Person'

Class PersonContainer
{
public List<Person> Persons{get; set;}
}

We have a Window class 'PersonViewModel' which has all the things with respect to the view. This class has a ObservableCollection which is bound to a Datagrid in my View and properties 'FirstName and LastName' are bound to the columns of the Datagrid.
The view contains button to 'Add/Remove/Modify' the records and 'Ok' and 'Cancel' button.

suppose we have PersonContainer object 'originalContainer' with 2 records. In the load event of the view, we create a copy/clone of PersonContainer with 2 records. Let's call it as clonedContainer. When we perform any operation(Add/Remove/Modify) through the dialog, we do it on clonedContainer. Once, we are done, on press of 'Ok' button, we just update originalContainer with the clonedContainer. On press of 'Cancel', we discard the 'clonedContainer' and set it to null.

Q: what could be the best way to handle 'Ok' and 'Cancel' in a dialog? Is creating a cloned object right way?

Part 2:
I have to implement the undo/redo of all the actions(Add/Remove/Modify the record) that happened on the Dialog. This has been implemented through the ICommand pattern with Execute/Unexecute methods. Whenever, we add a record, we add it the through the Execute method. However, we use the clonedContainer object and not the real one. In the Unexecute, I am using the 'originalContainer' instance and remove the added Person object. Now, if we perform 'Redo', we need to create the removed 'Person' object. By this time, clonedContainer is no more as it has been destroyed once we close the dialog.

Q: How can we implement undo/redo here?

Thanks in advance!!!

Rags
AnswerRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
cocis4826-Oct-12 11:13
cocis4826-Oct-12 11:13 
GeneralRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
Praveen Raghuvanshi27-Oct-12 7:39
professionalPraveen Raghuvanshi27-Oct-12 7:39 
AnswerRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
Eddy Vluggen27-Oct-12 4:34
professionalEddy Vluggen27-Oct-12 4:34 
GeneralRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
Praveen Raghuvanshi27-Oct-12 7:45
professionalPraveen Raghuvanshi27-Oct-12 7:45 
GeneralRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
cocis4827-Oct-12 16:01
cocis4827-Oct-12 16:01 
AnswerRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
BobJanova29-Oct-12 0:38
BobJanova29-Oct-12 0:38 
GeneralRe: Best way for 'OK' and 'Cancel' button implementation in a modal dialog Pin
Praveen Raghuvanshi31-Oct-12 7:59
professionalPraveen Raghuvanshi31-Oct-12 7:59 
QuestionInvoking a method using its 'string' name Pin
PozzaVecia26-Oct-12 8:28
PozzaVecia26-Oct-12 8:28 
AnswerRe: Invoking a method using its 'string' name Pin
jschell26-Oct-12 8:46
jschell26-Oct-12 8:46 
GeneralRe: Invoking a method using its 'string' name Pin
BobJanova29-Oct-12 0:40
BobJanova29-Oct-12 0:40 
GeneralRe: Invoking a method using its 'string' name Pin
jschell29-Oct-12 8:27
jschell29-Oct-12 8:27 
GeneralRe: Invoking a method using its 'string' name Pin
BobJanova29-Oct-12 23:37
BobJanova29-Oct-12 23:37 
GeneralRe: Invoking a method using its 'string' name Pin
jschell30-Oct-12 9:54
jschell30-Oct-12 9:54 
AnswerRe: Invoking a method using its 'string' name Pin
Clifford Nelson26-Oct-12 8:48
Clifford Nelson26-Oct-12 8:48 
GeneralRe: Invoking a method using its 'string' name Pin
PozzaVecia26-Oct-12 9:01
PozzaVecia26-Oct-12 9:01 
AnswerRe: Invoking a method using its 'string' name Pin
Clifford Nelson26-Oct-12 9:03
Clifford Nelson26-Oct-12 9:03 
AnswerRe: Invoking a method using its 'string' name Pin
BobJanova29-Oct-12 0:42
BobJanova29-Oct-12 0:42 

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.