Xaml Window Store Apps: Cannot set nullable properties in xaml - by Andrew S

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 771633 Comments
Status Closed Workarounds
Type Bug Repros 6
Opened 11/19/2012 11:15:29 AM
Access Restriction Public


It seems like there is a bug in the autogenerated code - XamlTypeInfo. Basically when you define a dependency property as a nullable type (e.g. int?) and try to set it in xaml you get an error indicating that the string you typed into xaml could not be used to create an IReference'1<Int32>
Sign in to post a comment.
Posted by JohnKozell on 2/5/2017 at 6:05 AM
2 years later, this is still not fixed? I just ran into this issue. I want to assign a simple value of "1" to an "Interval" property that is defined as double? and received the error "XamlCompiler error WMC0056: Cannot assign to nullable type on property Interval".
Why is this a difficult thing to fix, why do I have to add code to my project instead of just typing "1"?
Posted by Mike-EEE on 8/21/2015 at 7:48 AM
You guys have seriously hijacked and butchered Xaml. What a disgrace and embarrassment!!! You DO work for MSFT, right? Show some pride in your work and get these fundamental issues with Xaml fixed in UWP!! This stuff worked YEARS ago with WPF and Silverlight5!!! SERIOUSLY... who's side are you on??? Stop sitting around and collecting a paycheck and do some work!!!
Posted by Actipro Software on 3/19/2014 at 11:39 AM
I am running into this today. I am making a control that has a nullable primitive property defined. Regardless of the reason, it seems silly that if my property is a nullable int (int? in C#) that I can't just type a number in XAML to have it cast properly, or pass {x:Null} to define a null value. I agree with Andrew that the core primitives should all be covered.
Posted by Andrew S on 1/3/2013 at 6:00 AM
While I understand that you cannot handle all nullable types I would think that you could handle the basic types - i.e. intrinsic value types for which the runtime does deal with. At least in terms generated code for the .NET projects you could use the various static Parse methods. If you're not going to fix this in the runtime parsing them I'd rather you not change the xaml compiler. At least I could inject my own string parsing logic to deal with nullable types then. Actually I wish there was a way to do that for any unrecognized type rather than the behavior right now where the compiler does blow up for non-recognized types (e.g. custom structs).
Posted by Brian Chapman ex-MSFT on 1/2/2013 at 2:04 PM
Re-reading my previous post.... Let me attempt to be more clear.

The Conversion of strings into objects is done by the runtime time, except for user defined "enums", which are done in the generated code. The runtime does not convert user defined nullable property types correctly.

This problem will not be fixed in the next release, although fixing the XAML compiler to report an error at compile time could be.
Posted by Brian Chapman ex-MSFT on 12/3/2012 at 5:41 PM
The generated code only converts Enums from string. The runtime forwards anything it can't do to the generated code. There is some confusion because a nullable<int> is not an int. The generated code doesn't have access the to the Runtime's converters for everything (Brush for example) so it can't pick up the slack.

Support for nullables was discussed and is not in the plan for the next release. What *should happen* in the next release is the XAML compiler should error at compile time rather than the app crash at runtime.
Posted by Microsoft on 11/19/2012 at 11:31 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been reproduced and has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 11/19/2012 at 11:52 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)