This is a migrated thread and some comments may be shown as answers.

CellTemplateSelector : No matching constructor found on type.

7 Answers 256 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valentijn
Top achievements
Rank 1
Valentijn asked on 28 Sep 2010, 01:11 PM
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; }
    }

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 28 Sep 2010, 02:17 PM
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
0
Valentijn
Top achievements
Rank 1
answered on 28 Sep 2010, 03:12 PM
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.



0
Valentijn
Top achievements
Rank 1
answered on 28 Sep 2010, 03:19 PM
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;
        }
    }
}
 

0
Valentijn
Top achievements
Rank 1
answered on 28 Sep 2010, 03:24 PM
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.
0
Maya
Telerik team
answered on 28 Sep 2010, 04:20 PM
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
0
Francisco Amador
Top achievements
Rank 1
answered on 23 Nov 2010, 10:14 PM
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
0
Rob
Top achievements
Rank 1
answered on 24 Jul 2012, 11:40 PM
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
Tags
GridView
Asked by
Valentijn
Top achievements
Rank 1
Answers by
Maya
Telerik team
Valentijn
Top achievements
Rank 1
Francisco Amador
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Share this question
or