0

I am working on Windows 8.1 app.

I have a Page:

<Page d:DataContext="{d:DesignData /SampleData/MySampleData.xaml}" 
      x:Class="xxx.MyView"
      ...>
   <TextBlock Text="{Binding MyString}"/>
   <TextBlock Text="{Binding StartTime}"/>
</Page>

Then I have MySampleData.xaml:

<local:MyViewModel
 ...
 xmlns:local="using:xxx.ViewModels" 
 MyString="my text"
 StartTime="2014/01/01"/>

In MyViewModel.cs I have:

public class MyViewModel
{
    public string MyString {get; set;}
    public DateTime StartTime {get; set;}
}

In designer it displays correctly, but when compiling I get this error in my MySampleData.xaml:

Cannot assign text value '2014/01/01' into property 'StartTime' of type 'DateTime'

The part for MyString works perfectly, but the StartTime does not (it did in Windows 8.0), any idea how to get it working? And why does it try to compile the design data?

Additional Resources

According to this question, the reason is because WinRT does not support TypeConverters.

I saw this question, it proposes that you create a fake class, but I really want to do it in XAML.

Any ideas?

Community
  • 1
  • 1
Barnstokkr
  • 2,904
  • 1
  • 19
  • 34

1 Answers1

0

I created this class:

public class Jerry
{
    public DateTime SampleDateTime { get; set; }
}

And, using Blend, it created this sample data:

<App47:Jerry xmlns:App47="using:App47" 
    xmlns:System="using:System" 
    SampleDateTime="12/11/2014 17:00:25" />

Based on that, I think you just need to include the time string.

Best of luck!

Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
  • This is still a very weird issue (I do include System), it displays the data correctly in designer; but then cannot compile, it gives an error: **Cannot assign text value '12/11/2014 17:00:25' into property 'StartTime' of type 'DateTime'**. Which is very strange, why does it try to compile the design data? – Barnstokkr Dec 12 '14 at 07:16
  • Sorry, I should have been more clear in the question. I've updated it. – Barnstokkr Dec 12 '14 at 07:23
  • Have you tried starting from scratch with a simpler class? Just to prove this is a problem in XAML and not a problem with your class? – Jerry Nixon Dec 12 '14 at 17:43
  • 1
    Jip :P a few times. Even tried from a blank project. – Barnstokkr Dec 15 '14 at 06:56
  • Sorry about this. Since it works for me in a blank project, and doesn't work for you in a blank project, I am not sure where to go from here. Have you tried lighting a candle? (j/k) – Jerry Nixon Jan 05 '15 at 17:53
  • :D hehehe, thank you for all your effort, really appreciate it! I have actually given up on this, and will once again make time if I can find time to spend on it. – Barnstokkr Jan 06 '15 at 05:12