Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:39:57+00:00 2026-06-16T07:39:57+00:00

I have class, that selects the ItemDataTemplate for objects. But I can’t reference it

  • 0

I have class, that selects the ItemDataTemplate for objects. But I can’t reference it in my XAML code. (Page.Resources).

It’s the Items page in XAML. The class is in the commons folder, and I’ve referenced the commons folder here:

xmlns:common="using:Sample_App.Common"

and then when I wan’t to add it to my XAML:

<common:MyDataTemplateSelector x:Key="Selector" AdTemplate="{StaticResource Ad}" NormalTemplate="{StaticResource Normal}"></common:MyDataTemplateSelector>

I get the following error:

The name “MyDataTemplateSelector” does not exist in the namespace “using:MyDataSelector”

Here’s the MyDataSelector class:

namespace MyDataSelector
{
    private class MyDataTemplateSelector : DataTemplateSelector
    {
        public DataTemplate NormalTemplate { get; set; }

        public DataTemplate AdTemplate{ get; set; }

        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            if (item is TestApp.Mainpage.NormalData)
                return NormalTemplate
            if (item is TestApp.Mainpage.AdData)
                return AdTemplate;

            return SelectTemplateCore(item, container);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:39:58+00:00Added an answer on June 16, 2026 at 7:39 am

    You have a couple problems with your code. First of all, you mention that your class is in “the commons folder” – this is totally irrelevant. The location of a code file generally doesn’t matter to the compiler, but the namespace you declare the class in does matter.

    namespace MyDataSelector // <- This is where your class can be found
    {
        private class MyDataTemplateSelector : DataTemplateSelector
        {
    

    So since your class is in the namespace MyDataSelector, the reference in your xaml files should look something like this:

    <Page x:Class="WpfApplication1.Page1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:myDataSelector="using:MyDataSelector">
    

    And you would reference your class like this:

    <myDataSelector:MyDataTemplateSelector />
    

    Another issue is that your class is declared as private. That doesn’t make sense and probably won’t compile. Remove private to make your class internal, or change it to public.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MyDBAdapter class, that can do selects, but I also need to
I have a page with 5 selects that all have a class name 'ct'.
Say I have a tableview class that lists 100 Foo objects. It has: @property
I have a script that selects and drags several elements. It works fine but
I have a WPF-page (ZorgTrajectPage1.xaml) with a code-behind ZorgTrajectPage1.xaml.cs with a DependencyProperty ZorgtrajectController called
I have a method that fills a ListBox with objects (custom class) internal void
I have a simple jQuery selector that selects all links without a class of
How to select next n hidden elements that have class foo using jQuery?
I am attempting to select all a hrefs that do not have the class
I have a xml that looks like below <xsl:template match=//xml> <xsl:for-each select=//z:row> <ul class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.