CellTemplateSelector : No matching constructor found on type.

8 posts, 0 answers
  1. Valentijn
    Valentijn avatar
    21 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    Hi

    I'm trying to use a celltemplateselector in my gridview but am receiving the error:

    No matching constructor found on type 'Bass.Helpers.MyTemplateSelector'.

    Could anybody please help me here, since this is driving me nuts. I can't see what I'm doing wrong.

    I'm using this in xaml:

    xmlns:local="clr-namespace:Bass.Helpers"

    (in grid.resources) :
    <local:MyTemplateSelector x:Key="templateSelector">
                    <local:MyTemplateSelector.Deleted>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"
                           TextDecorations="Strikethrough"/>
                        </DataTemplate>
                    </local:MyTemplateSelector.Deleted>
                    <local:MyTemplateSelector.Normal>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"/>
                        </DataTemplate>
                    </local:MyTemplateSelector.Normal>
                </local:MyTemplateSelector>

    (in my gridview):
    <telerik:GridViewDataColumn CellTemplateSelector="{StaticResource templateSelector}" UniqueName="GlobalizedDescription.Dutch" Header="{Binding Path=stringResources.lblCommitteeName, Source={StaticResource LocalizedStrings}}" DataMemberBinding="{Binding GlobalizedDescription.Dutch}"></telerik:GridViewDataColumn>

    i have a class in my namespace Bass.Helpers defined as follows:
     class MyTemplateSelector : DataTemplateSelector
        {
            public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
            {
                if (item is Bass.Web.DataModel.Committee)
                {
                    Bass.Web.DataModel.Committee committee = item as Bass.Web.DataModel.Committee;
                    if (committee.Deleted == true)
                    {
                        return Deleted;
                    }
                    else
                    {
                        return Normal;
                    }
                }
                return null;
            }
            public DataTemplate Deleted { get; set; }
            public DataTemplate Normal { get; set; }
        }
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Sep 2010 Link to this post

    Hello Valentijn,

    On exploring the code-snippet you have provided, I am not able to see anything wrong with it. The only thing I may suggest is to make sure that you are setting the right reference towards System.Windows.Controls.DataTemplateSelector. However, in order to provide you with a more appropriate solution, I would need more information about your project and its settings.
     

    Sincerely yours,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Valentijn
    Valentijn avatar
    21 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    Hi

    It was indeed using the one in telerik.windows...

    But now things get even worse!

    I get a Error    2    The type or namespace name 'DataTemplateSelector' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?)    C:\DEV_BASS\BASS\Bass\Helpers\MyTemplateSelector.cs    15    56    Bass

    Although i have a reference to System.Windows.Controls and all my other stuff is working perfectly. My runtime version of System.Windows.Controls is v2.0.50727. Maybe there is a different newer or older version out there? I just downloaded the latest version of .net framework and silverlight tools and it did not help.



  4. Valentijn
    Valentijn avatar
    21 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    Hi

    In my opinion, there is a mistake in your documentation:
    ms-help://telerik.windows.controls.Silverlight/telerik.windows.controls.gridview/gridview-cell-template-selector.html

    This is documentation for silverlight but The class DataTemplateSelector does not exist in Silverlight. It is a WPF only thing !!!

    Please update your documentation correctly since this is very annoyiong to anybody who runs into this issue!

    The solution would be to copy the DataTemplateSelector base class from the WPF assembly (via Reflector).

    // code from WPF

    using System;
    using System.Windows;

    namespace System.Windows.Controls
    {
        // Summary:
        // Provides a way to choose a System.Windows.DataTemplate based on the data
        // object and the data-bound element.
        public class DataTemplateSelector
        {
            // Summary:
            // Initializes a new instance of the System.Windows.Controls.DataTemplateSelector
            // class.
            public DataTemplateSelector()
            {
            }

            // Summary:
            // When overridden in a derived class, returns a System.Windows.DataTemplate
            // based on custom logic.
            //
            // Parameters:
            // item:
            // The data object for which to select the template.
            //
            // container:
            // The data-bound object.
            //
            // Returns:
            // Returns a System.Windows.DataTemplate or null. The default value is null.
            public virtual DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                return null;
            }
        }
    }
     

  5. Valentijn
    Valentijn avatar
    21 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    My solution does not work. I again get the same error with the constructor as before. Does anybody have any idea how to get this to work with silverlight? The example in the documentation does not work.
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Sep 2010 Link to this post

    Hello Valentijn,

    Please excuse me for the misunderstanding. Indeed, you are quite right - the System.Windows.Controls.DataTemplateSelector is used only for WPF in this case. Our documentation has been immediately fixed.
    Considering your problem, the cause for it may be that the class - MyTemplateSelector - cannot be accessed. Thus all you need to do is to add the "public" identifier in front. Still I am sending you a sample project that you can use as a further reference.
     

    Kind regards,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Francisco Amador
    Francisco Amador avatar
    41 posts
    Member since:
    Mar 2010

    Posted 23 Nov 2010 Link to this post

    I ran into the same issue until I found this thread. Please also change in the documentation to include the public identifier in front of the class definition. As it stands, copying the documentation still causes the xaml parsing error.

    Thank you
  8. Rob
    Rob avatar
    5 posts
    Member since:
    Apr 2012

    Posted 24 Jul 2012 Link to this post

    same issue. took me ages to fix. can you guys update your documentation to save people the pain of finding out whats wrong. http://www.telerik.com/help/silverlight/gridview-cell-template-selector.html
Back to Top