KeyedCollection and d:DataContext Design Error

后端 未结 3 811
自闭症患者
自闭症患者 2021-01-03 10:54

See the update below for VS2013.

When using a class as a d:DesignInstance that exposes a KeyedCollection, the XAML desig

相关标签:
3条回答
  • 2021-01-03 11:15

    If I have'nt misunderstood your question try it like

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:WpfApplication1"
        Width="800" Height="800"
        Title="MainWindow"   
        >
    <Window.DataContext>
        **<local:MyClass />**
    </Window.DataContext>
    <Grid x:Name="LayoutRoot">
    </Grid>
    

    I hope this will help.

    0 讨论(0)
  • 2021-01-03 11:21

    I had to remove the Default Constructor from my DesignInstance-Class

    0 讨论(0)
  • 2021-01-03 11:38

    I've been able to resolve this issue by prefixing the design instance type with "d:Type" as such:

    d:DataContext="{d:DesignInstance d:Type=local:MyClass}"
    

    This seems to be a bug in the VS2013 designer. I believe the d:Type property should be the default property of the d:DesignInstance attribute. Also, strangely I've only seen this issue with the KeyedCollection class.

    Furthermore, the MSDN examples of d:DesignInstance usage sometimes use "Type" with no prefix. In this example if d:Type is omitted or the prefix is missing, the design time error is generated as I mentioned.

    0 讨论(0)
提交回复
热议问题