XAML test data - the designer can convert types, but the runtime cannot

I am creating a user control to display a note. Therefore, I have a NoteViewModel. In my designer I want to have a test note. Therefore, in my XAML there is the following:

<UserControl.Resources>
    <local:NoteViewModel x:Key="ViewModel" d:IsDataSource="True">
        <local:NoteViewModel.Note>
            <localweb:Note
                NoteID="1"
                CreatedBy="Some Guy"
                CreatedDate="2010-01-01 8:00 AM"
                Category="Some Category"
                NoteText="Some Text"
                />
        </local:NoteViewModel.Note>
    </local:NoteViewModel>
</UserControl.Resources>

This works great during development. But at runtime, I get errors in that I cannot convert “1” to Int32 and cannot convert “2010-01-01 8:00 AM” to DateTime. Why can a developer handle this, but not at runtime? How can I change my XAML so that the designer can show the test note, but the runtime will not work?

+3
source share
2

, , Int, NoteID:

    <localweb:Note xmlns:sys="clr-namespace:System;assembly=mscorelib" ...>
        <localweb:Note.NoteID><sys:Int32>1</sys:Int32></localweb:Note.NoteID>
    </localweb:Note>

, , , .

+1

, XAML.

, "1" Int32, int , Xaml . CreatedDate TypeConverterAttribute: -

 [TypeConverterAttribute(typeof(DateTimeTypeConverter))]
 public CreatedDate { get; set; }

xaml , . , , , , Xaml - . , .

0

Source: https://habr.com/ru/post/1759140/


All Articles