0

I have a large and long running WPF solution currently running in VS 2017. When I migrated from VS 2015, I saw an unusual designer error where instead of showing the design time values from binding to the VM, it would show the property names for nullable properties (e.g., "SomeViewModel.ADoubleNullable" for a double? property) and the default values of the data types for the design time values and not the ones set on the object.

If I switch back to VS 2015 I don't see the issue. Here is what is interesting: if I create a new WPF project in the same solution from scratch with the same settings (4.6.1 with all the defaults), with the same dummy data model and same window, I don't see the problem! And of course, it works at run time just fine.

Here is my VM:

public class DataModel
{
    public double NormalDouble { get; set; } = 1;
    public double? NullableDouble { get; set; } = 2;
    public Child Child { get; set; } = new Child();
}

public class Child
{
    public double NormalDouble { get; set; } = 1;
    public double? NullableDouble { get; set; } = 2;
}

Here is the View:

<StackPanel d:DataContext="{d:DesignInstance local:DataModel, IsDesignTimeCreatable=True}">
    <StackPanel>
        <TextBox Text="{Binding NormalDouble}"/>
        <TextBox Text="{Binding NullableDouble}"/>
        <TextBox Text="{Binding Child.NormalDouble}"/>
        <TextBox Text="{Binding Child.NullableDouble}"/>
    </StackPanel>
</StackPanel>

I would expect to see "1,2,1,2" and this is the case in a new WPF project. But in my old project, I see "0, NullableDouble, 0, ChildDataModel.NullableDouble".

Anyone seen anything like this or have suggestions on how to troubleshoot? I have tried dropping the IsDesignTimeCreatable attribute, different computers, and deleting the ".vs" folder. I have seen this issue since the first VS 2017 RC until the recent 15.2 (26430.4).

  • I can't answer your actual question. I expect that to know for sure what the difference is between a legacy project upgraded to VS2017 and a fresh VS2017 project, you'd have to carefully inspect the .csproj, .xaml, and generated .cs files to see what changed. But, you might want to look at these for ideas: https://stackoverflow.com/questions/2716757/how-to-set-properties-of-a-ddesigninstance-in-xaml, https://stackoverflow.com/questions/15030381/keyedcollection-and-ddatacontext-design-error, and https://msdn.microsoft.com/en-us/library/dd490796.aspx. – Peter Duniho Jun 13 '17 at 23:24
  • There are minor differences in syntax; in theory I'd expect all variations to work, but note that in some examples, they use `d:DesignData` instead of `d:DesignInstance`, or explicitly specifying the type property name (i.e. either `Type` or `d:Type`). Maybe slight changes to the syntax would change the behavior. – Peter Duniho Jun 13 '17 at 23:24
  • You ... you just said you already have the solution? Create a new project and migrate all your code over? Well, do that. And open a connect bug report. –  Jun 14 '17 at 12:30
  • Peter, thanks. Doesn't help my problem, but I hadn't see the "d:DesignProperties.DataContext" syntax before. Also, I could use DesignData, but some of my properties are painful to expose that way (like points for charts and thinks like that). – JohnnyLightning Jun 15 '17 at 19:42
  • Will, I never said I had a solution. I said when I create a new project in VS 2017, I don't see the problem when I put in the above simple Views/ViewModels. If I actually recreate the actual complex project from scratch and migrate all my existing Views/ViewModels over, I again have the same issue even when adding the simple V/VM's I mentioned. No problems when working on the same project in VS 2015. So something in my project is causing a bug in the XAML designer even when extremely simple views/viewmodels are added. – JohnnyLightning Jun 15 '17 at 19:55
  • Peter, I also wanted to clarify. I have done every variation on the syntax including the ones you mentioned and those in the referenced articles. – JohnnyLightning Jun 15 '17 at 19:57
  • Hit this myself. Looking around I think it only works on AnyCPU/X86, not X64. Needs the "enable design data" option which isn't available on X64 projects (from this SO answer) https://stackoverflow.com/a/42492439/7262 – MarcE Dec 14 '17 at 11:10
  • I'm experiencing this as well. However, my project has been written from VS2017 from the start, and x86/x64/Any CPU does not seem to make any difference either. – whatsisname Mar 11 '19 at 18:25
  • The issue is that the designer does not allow code to run in design time in anything other than x86. See MarcE's answer above. Didn't actually see his response until just now - but simply switching from AnyCPU to x86 did it! – JohnnyLightning Mar 12 '19 at 20:53

0 Answers0