Reputation: 2514
In my xaml file for window in wpf project am using binding to the type in such way
<TreeView>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type spec:SectionContainer.SectionNode}">
...
where SectionContainer.SectionNode
is subclass of partial class SectionContainer
and spec
is namespace of current assembly, defined in Window
tag as:
xmlns:spec="clr-namespace:Proj.Sections".
There is no error while defining spec
, but using SectionNode type in DataType property generates:
Cannot find the type 'spec:SectionContainer.SectionNode'. Note that type names are case sensitive.
I understand what this error means, but there is no reason for it to appear there. May be problem in using of partial class or in something else? All classes are defined as public
.
My classes:
namespace Proj.Sections
{
[Serializable]
public partial class SectionContainer : INotifyPropertyChanged
{
[Serializable]
public class SectionNode : SectionNode
{
}
}
}
Upvotes: 0
Views: 511
Reputation: 69979
Ahh... now that you have added your class definitions (please always show your relevant code when you ask your question), I think that I can see your problem. I had a similar situation where Serialization
was the problem. For some unknown reason, it doesn't work well with the INotifyPropertyChanged
interface.
To get around this problem, my WPF projects all have separate SerializableXXX
classes for any objects that need serialization and the classes that are used in the UI and implement the INotifyPropertyChanged
interface have no serialization. As a simple test, try removing your SerializableAttribute
s and see if it makes any difference.
Upvotes: 1
Reputation: 2514
Moving SectionNode
subclass out of SectionContainer
solves the problem. Before this I also tried to define DataType
value in separate <HierarchicalDataTemplate.DataType/>
tag, but it led to another error messages. So other ideas how to use subclasses and have no errors in the same time are welcomed.
Upvotes: 0