Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Won't Fix Help for as Won't Fix


8
0
Sign in
to vote
Type: Bug
ID: 771633
Opened: 11/19/2012 11:15:29 AM
Access Restriction: Public
0
Workaround(s)
view
2
User(s) can reproduce this bug

Description

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>
Details
Sign in to post a comment.
Posted by Bill Henning [Actipro] 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 _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 _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)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
Win8Issues - Copy.zip 11/19/2012 24 KB