0

Getting a compiler error on

src:FieldDefUsrFldUsrs

Error 8 The tag 'FieldDefUsrFldUsrs' does not exist in XML namespace 'clr-namespace:Gabe2a'. Line 14 Position 10. C:\My Dev\CommonSource\Gabriel\Gabe2a\Gabe2Acollection\Gabe2aI55\PageSearchFieldUsrFld.xaml 14 10 Gabe2a

How to fix this error?

<Page x:Class="Gabe2a.PageSearchFieldUsrFld"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
      DataContext="{Binding RelativeSource={RelativeSource self}}"
      xmlns:local="clr-namespace:Gabe2a"
      xmlns:src="clr-namespace:Gabe2a"
      ShowsNavigationUI="False"
    Title="PageSearchFieldUsrFld">
    <Page.Resources>
        <src:FieldDefUsrFldUsrs x:Key="MyList"/>
        <HierarchicalDataTemplate DataType = "{x:Type src:League}"
                                ItemsSource = "{Binding Path=Divisions}">
            <TextBlock Text="{Binding Path=Name}"/>
        </HierarchicalDataTemplate>

namespace Gabe2a
{
    public partial class PageSearchFieldUsrFld : Page
    {            
        private List<GabeLib.FieldDefUsrFldUsr> fieldDefUsrFldUsrs = new List<GabeLib.FieldDefUsrFldUsr>();
        public List<GabeLib.FieldDefUsrFldUsr> FieldDefUsrFldUsrs { get { return fieldDefUsrFldUsrs; } }

namespace Gabe2a {
    public class GabeLib : INotifyPropertyChanged
    {
        [Serializable()]
        public class FieldDefUsrFldUsr 
        {
paparazzo
  • 44,497
  • 23
  • 105
  • 176

1 Answers1

0

Well, you try to instantiate nested class in XAML and that`s still no-no in WPF. See this answer for some details on the issue and MSDN link that states a rule for custom classes to be used in XAML:

Your custom class must not be a nested class. Nested classes and the "dot" in their general CLR usage syntax interfere with other WPF and/or XAML features such as attached properties.

That`s still relevant for framework version 4.5.

As to how to avoid this... Is there any real reason for you to use nested classes? Simply using dotted namespaces is usually enough for project organization:

namespace Gabe2a.GabeLib 
{
    public class GabeLib : INotifyPropertyChanged         
    {}

    [Serializable()]
    public class FieldDefUsrFldUsr 
    {}
}

So it seems you can`t instantiate nested class in XAML but you still can use it in DataTemplates and such without changing your current class structure:

<DataTemplate DataType="{x:Type local:GabeLib+FieldDefUsrFldUsr}">
    ...
</DataTemplate>
Community
  • 1
  • 1
icebat
  • 4,696
  • 4
  • 22
  • 36