Designer rejects DataTemplate.DataType

I am trying to embed some WPF into my current Windows Forms Application. When I use this simple custom control, the constructor for that control does not reload.

This only happens in this app. If I create a clean Windows Forms project add these files the designer works great.

I tried restarting Visual Studio and cleaned / rebuilt the application.

Any ideas? (This is for items in a ListBox, so x: Key is not an option.)

PS How can I get rid of all those blank lines in my codelist?

DETAILS:

MyClasses.cs

namespace MyNamespace {
  internal class MyClassInternal {}
  public class MyClassPublic {}
}

      

MyUserControl.xaml

<UserControl x:Class="MyNamespace.MyUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyNamespace"         
    Height="300" Width="300">

    <UserControl.Resources>
        <DataTemplate DataType="{x:Type local:MyClassInternal}"/> <!--OK-->

        <ObjectDataProvider x:Key="ClassPublicKey" ObjectType="{x:Type local:MyClassPublic}"/> <!--OK--> 

        <!-- Type reference cannot find public type named 'MyClassPublic' -->
       <DataTemplate DataType="{x:Type local:MyClassPublic}"/> <!--FAILS-->
    </UserControl.Resources>

    <TextBlock>Hello World</TextBlock>
</UserControl>

      

MyUserControl.xaml.cs

using System.Windows.Controls;

namespace MyNamespace {
    public partial class MyUserControl :UserControl {
        public MyUserControl() {
            InitializeComponent();
        }
    }
}

      

+1


a source to share


1 answer


This is caused by the presence of a space in the Assembly name.



+2


a source







All Articles