The types DateOnly
and TimeOnly
do not get XAML serialized
#10529
Labels
📭 waiting-author-feedback
To request more information from author.
Description
Variables of types
DateOnly
andTimeOnly
do not get serialized when converted to XAML. This is not the case for other date-related standard types likeDateTime
orDateTimeOffset
.Reproduction Steps
Run the following function in a NET8 environment:
Expected behavior
Variables of type
DateOnly
andTimeOnly
should be correctly serialized byXamlServices.Save(...)
.Actual behavior
After running the function, notice that:
s1
is<?xml version="1.0"?> <DateOnly xmlns="clr-namespace:System;assembly=System.Private.CoreLib"/>
s2
is<?xml version="1.0"?> <TimeOnly xmlns="clr-namespace:System;assembly=System.Private.CoreLib"/>
s3
is<?xml version="1.0"?> <DateTime xmlns="clr-namespace:System;assembly=System.Private.CoreLib">2025-03-07T21:49:03Z</DateTime>
Regression?
As far as we know this is not a regression.
Known Workarounds
We have found no workaround so far. We have attempted to follow the steps from https://learn.microsoft.com/en-us/dotnet/desktop/xaml-services/define-custom-types and define custom converters for
DateOnly
andTimeOnly
and then usedTypeDescriptor.AddAttribute(...)
in order to map the converter to each of the types, but XAML serialization still did not occur. Also, we noticed that the converterDateTimeConverter2
exists inSystem.Xaml
which probably explains whyDateTime
does get serialized correctly.Impact
No response
Configuration
OS: Windows 11 on an x64 CPU
NET version: 8.0
Other information
No response
The text was updated successfully, but these errors were encountered: