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

[Solved] Strange behavior binding DynamicObject on GridViewImageColumn

2 Answers 182 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sébastien
Top achievements
Rank 1
Sébastien asked on 02 Aug 2011, 07:06 PM
I have two questions about binding on RadGridViewColumn.

I created a simple grid and use a array of data (a clasic CLR class... not dynamic) as itemsource.

        <telerik:RadGridView AutoGenerateColumns="False" x:Name="datagrid" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewImageColumn DataMemberBinding="{Binding ImageUrl,Converter={StaticResource convert}}" Header="Image" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Title,Converter={StaticResource convert}}" Header="Titre" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

I use the converter  to display Debug Information.
  public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Debug.WriteLine(string.Format("[Converter] Value : {0} / TargetType : {1}", value, targetType.Name));
            return value;
        }

My data (as items source is) :
            Model[] vals = new Model[]
            {
                new Model() { Title = "TestStatic", ImageUrl = "teststaticurl.html" },
            };

When I execute, I got :
[Converter] Value : teststaticurl.html / TargetType : Object
[Converter] Value : teststaticurl.html / TargetType : ImageSource

[Converter] Value : TestStatic / TargetType : Object

My first question is : Why two calls are made to the converter for the GridViewImageColumns ? (one with Object as targetType and the other with ImageSource)

Then I try to use the samedatagrid with an object derived from DynamicObject :
    public class ModelDynamic : DynamicObject
    {
        public override System.Collections.Generic.IEnumerable<string> GetDynamicMemberNames()
        {
            return new string[] { "Title""ImageUrl" };
        }

        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            string name = binder.Name;
            result = "";
            if (name == "Title")
                result = "TestDynamic";
            else if (name == "ImageUrl")
                result = "testdynurl.html";
            return true;
        }

    }

When I execute, I got :
[Converter] Value : testdynurl.html / TargetType : Object
System.Windows.Data Error: BindingExpression path error: 'ImageUrl' property not found on 'RadGridViewTest.ModelDynamic' 'RadGridViewTest.ModelDynamic' (HashCode=60620523). BindingExpression: Path='ImageUrl' DataItem='RadGridViewTest.ModelDynamic' (HashCode=60620523); target element is 'System.Windows.Controls.Image' (Name=''); target property is 'Source' (type 'System.Windows.Media.ImageSource')..

[Converter] Value : TestDynamic / TargetType : Object

The data for the GridViewDataColumn work correctly, but I don't understand why the second call to the converter for the GridViewImageColumn failed saying it couldn't found the property... property it has found before by calling the converter the first time with the correct value.

Sorry if the question is not really clear (not very simple to explain in word). I upload a sample project to reproduce the problem on my Skydrive : RadGridViewDynamicBug

Thanks in advance for your answer.

Note : I use version 2011.2.712.1040

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Aug 2011, 08:32 AM
Hello Sébastien,

The problem is fixed and the fix will be part of our latest build later Today. I've added 2000 Telerik points to your account. 

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Sébastien
Top achievements
Rank 1
answered on 08 Aug 2011, 06:57 PM
I tested the new internal build (2011.2.808.1040).

1) for binding with CLR object, I still have the same strange behavior (converter called twice for GridViewImageColumn). 
2) for binding on dynamicobejct, the binding error disappear but the target type in the converter called by GridViewImageColumn should be ImageSource and not 'object'.
Tags
GridView
Asked by
Sébastien
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Sébastien
Top achievements
Rank 1
Share this question
or