Problems with xaml

Dec 15, 2009 at 7:41 PM

Hello, firstly I would like to congratulate for this framework. It's fantastic.

I have a problem in the code generated for an interface. This entity in question contains a property that is an abstract class.

When I navigate to that form is the result:
'AssociatedValue' value can not be assigned to property 'Route' of object 'Signum.Windows.EntityLine'. Field not found for property AssociatedValue Error at object 'Signum.Windows.EntityLine' in markup file 'DBED.Windows; component / controls / devices / property.xaml' Line 12 Position 56.


I have other similar cases that run without any problem. When I navigate there everything goes well and when I try to create the property asks me what kind of concrete classes is that I want.

Can give me some kind of help or suggestions?

Thank you and keep up the good work =)

Coordinator
Dec 16, 2009 at 12:09 PM

I need a little bit more of info, could you please send me some code of the Entities involved and the Xaml code.

Also, think that m:Common.Route, opossed to WPF Binding, is very strongly typed and strict, so you can not:

* Use properties that are defined at runtime by the objects
Neither you can use members defined in an interface!

The reason is that, even if both Lion and Cat have a head property, they live in different columns and could potentially have different implementations on each, also they could have different permissions (but that's something only related to Signum.Framework.Extensions, comming soon) and the control needs to know that on Load Time.

In order to do that you will need to instantiate a hand made control for each 'Animal' on DataContextChange.

I hope my answer has something to do with your problem.

Cheers!

Olmo

 

Dec 16, 2009 at 3:59 PM

Thanks for the help. However I could not solve the problem there.
It is a quite simple and I think that wasn't doing anything wrong, because I used similar situations in other entities and things are going well.

Some Code:

[Serializable]
public class PropertyDN : Entity
{
        ...  
        ValueDN _value;
        public ValueDN AssociatedValue
        {
            get { return _value; }
            set { Set(ref _value, value, "AssociatedValue"); }
        }
        ...
}

 

   [Serializable, ImplementedBy(typeof(ArrayValueTypeDN),typeof(ScalarValueTypeDN),typeof(EnumValueTypeDN))]
    public abstract class ValueDN : Entity
    {
        [NotNullable, SqlDbType(Size = 100)]
        string name;
        [StringLengthValidator(AllowNulls = false, Min = 1, Max = 100)]
        public string Name
        {
            get { return name; }
            set { SetToStr(ref name, value, "Name"); }
        }

        public override string ToString()
        {
            return name;
        }
    }

    [Serializable]
    public class EnumValueTypeDN : ValueDN
    {...}

    [Serializable]
    public class ScalarValueTypeDN : ValueDN
    {...}

    [Serializable]
    public class ArrayValueTypeDN : ValueDN
    {
       ...
        ConversionDN conversion;
        public ConversionDN Conversion
        {
            get { return conversion; }
            set { Set(ref conversion, value, "Conversion"); }
        }
    }

 

[Serializable, ImplementedBy(typeof(ConversionFormulaDN), typeof(ConversionObjectDN))]
    public abstract class ConversionDN : Entity
    {...}

    [Serializable]
    public class ConversionFormulaDN : ConversionDN
    {...}

    [Serializable]
    public class ConversionObjectDN : ConversionDN
    {...}

well my case is, when I try to create a new 'PropertyDN' in the xaml form I get the error on the first post "Field not found for property AssociatedValue" , however when I try to create a new 'ArrayValueTypeDN' in the xaml form, the app shows me the page correctly and when I try to create an element 'ConversionDN' the app asks me a popup to select the type of conversion I want ( 'ConversionFormulaDN' or 'ConversionObjectDN').

this is wearded because is the same case and works diferently.

I do not want to abuse your patience, but if you want to look at the solution is in http://uploading.com/files/fe71cadm/DomoBus_EnvironmentDesign.zip/

I'm with this error a week ago and i'm out of ideas

 

Thank's for your help =)

 

Coordinator
Dec 17, 2009 at 9:57 AM

There are two small problems here:

1-  The first one is conceptual, when you use ImplementedBy over a Type the real meaning is DefaultImplementedByOnFieldsThatReferToMe, so really you are creating an implicit field like this.

[Serializable]
public class PropertyDN : Entity
{
        ...   
       [ImplementedBy(typeof(ArrayValueTypeDN),typeof(ScalarValueTypeDN),typeof(EnumValueTypeDN))]
ValueDN _value; public ValueDN AssociatedValue { get { return _value; } set { Set(ref _value, value, "AssociatedValue"); } } ... }
The reason is that in Signum Framework prolymorphism is a feature of Foreign Keys, not tables per-se.  
I'm considering spliting up ImplementedBy and ImplementedByAll in two, a DefaultImplementedByXXX for Types only and a ImplementedByXXX for fields only.
2.- What is causing the real problem is the name. When you bind in WPF using common Route (os ASP.Net MVC when we deploy Signum.Web) you are binding to the Property, but the information for implementations is found in the field. 
In order to make the Implementation negociation automatic you need field and property to have a similar name. The current algorithm is like this: 
        public static PropertyInfo FindPropertyInfo(FieldInfo fi)
        {
            return (fi.DeclaringType.GetProperty(CleanFieldName(fi.Name), BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public));
        }

        public static string CleanFieldName(string name)
        {
            if (name.Length > 2)
            {
                if (name.StartsWith("_"))
                    name = name.Substring(1);
                else if (name.StartsWith("m") && char.IsUpper(name[1]))
                    name = Char.ToLower(name[1]) + name.Substring(2);
            }

            return name.FirstUpper();
        }
So, basically we allow, it to start by '_', 'm', and have different casing.  
This doesn't work for: 
ValueDN _value;
public ValueDN AssociatedValue

It should work if you change _value to _associatedValue. 
Cheers!

 

Dec 21, 2009 at 12:59 PM
olmo wrote:
It should work if you change _value to _associatedValue.

Thanks for your explanation, it really works.

Cheers!