I need to hold the selected ListView Item in a temporary variable.

Ronald Rex 1,666 Reputation points
2023-06-08T18:53:07.3566667+00:00

I need to hold the selected ListView Item in a temporary variable so that the user can Cancel an Edit operation and the ListView Item will revert back to its original values. I can't understand why Temporaryselectedudf changes to the SelectedUdf value. Thanks !

Model
public class UserDefinedFields : INotifyPropertyChanged 
{ protected bool doOnChange; 	
  private int _id; 	
  private string _name;
....

View Model
[ObservableProperty] 	
UserDefinedFields _selectedUdf;
....

var tmp = new UserDefinedFields(); 		
tmp=SelectedUdf; 		
Temporaryselectedudf = tmp;


.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,920 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,301 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 56,926 Reputation points
    2023-06-08T19:29:05.8933333+00:00

    that's because class instance assign is by ref, not a copy:

    public class MyClass
    { 
        public int Value;
    }
    
    var a = new MyClass { Value = 1};
    var b = a;  // b points to the same instance as a
    Console.WriteLine(a.Value); // 1
    b.Value = 2;
    Console.WriteLine(a.Value); // 2 
    
    

    so in your case store the items values in a variable(s), and restore


0 additional answers

Sort by: Most helpful