MyControl.Margin.Left = 10;
Error:
Cannot modify the return value of ‘System.Windows.FrameworkElement.Margin’ because it is not a variable
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that
Marginis a property, and its type (Thickness) is a value type. That means when you access the property you’re getting a copy of the value back.Even though you can change the value of the
Thickness.Leftproperty for a particular value (grr… mutable value types shouldn’t exist), it wouldn’t change the margin.Instead, you’ll need to set the
Marginproperty to a new value. For instance (coincidentally the same code as Marc wrote):As a note for library design, I would have vastly preferred it if
Thicknesswere immutable, but with methods that returned a new value which was a copy of the original, but with one part replaced. Then you could write:No worrying about odd behaviour of mutable value types, nice and readable, all one expression…