Frage

I have a object named "item" witch is passed to method from XAML

This is what I get on breakpoint:

base {System.Reflection.TypeInfo} = Name = "Country" Full/Name = "Playground.Domain.Country"}

I'm trying to find how can I found of which "Type" is the item by

public class EditorTemplateSelector : DataTemplateSelector
    {
      public override DataTemplate SelectTemplate(object item,
                                                  DependencyObject container)
      {
        DataTemplate template = null;
        var templateName = "NotFoundEditor";
        if (item != null)
        {
          FrameworkElement element = container as FrameworkElement;
          if (element != null)
          {
            if (item is City)
              templateName = "CityEditor";
            else if (item is Country)
              templateName = "CountryEditor";

            template = element.FindResource(templateName) as DataTemplate;
          }
        }
        return template;
      }

but with no luck.

The object item get its data from

public Type ModelType
{
  get { return typeof(T); }
}

Any suggestions?

War es hilfreich?

Lösung

In the light of your last edit:

If "item" is a "System.Type" and not an instance of it, then use:

   if(item == typeof(City))

Andere Tipps

Could you try to see if you have multiple instance of "Playground" assembly in AppDomain.CurrentDomain.GetAssemblies() ?

This may happen if you're referencing this assembly from another project via a dll reference (you chose via "browse" in "add reference" dialog), and not a project reference.

In other words: this kind of odd things happens when you're referencing two different versions of the same assembly.

[edit] if it's that, it has nothing to do with xaml

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top