views:

134

answers:

1

Hello All,

Am new to XAML/WPF and have come across this weird issue:

I have a list view to which I set a DataSource. The DataSource is an arraylist of "CatalogPartRows". I create my columns in the code. I then set their cell templates (some of my columns contain combo boxes and check boxes). My problem here is that I need to call a function in the "CatalogPartRow" class which fetches the string that I need to set in a cell.

Here is the code I am trying to use:

            // THIS DOES NOT WORK
            //
            ObjectDataProvider ODP = new ObjectDataProvider();
            ODP.MethodName = "PropertyValueAsString";
            ODP.MethodParameters.Add(PropertyName);
            ODP.ObjectType = typeof(CatalogPartRow);

            Binding DataBindingText = new Binding();
            DataBindingText.Source = ODP;

            // THIS WORKS
            //
            //String BindingPathText = /*NOXLATE*/"PropertyValues[" + CPR.IndexOf(PropertyName) + /*NOXLATE*/"]";
            //Binding DataBindingText = new Binding(BindingPathText);

            FrameworkElementFactory TextBlockElement = new FrameworkElementFactory(typeof(TextBlock));
            TextBlockElement.SetBinding(TextBlock.TextProperty, DataBindingText);

            FrameworkElementFactory PropertyColumnElement = new FrameworkElementFactory(typeof(Grid));
            PropertyColumnElement.AppendChild(TextBlockElement);

            DataTemplate DT = new DataTemplate();
            DT.VisualTree = PropertyColumnElement;

            GVC.CellTemplate = DT;

Is my approach correct?

CPR = CatalogPartRow

GVC = GridViewColumn

Thanks, Raj.

A: 

Since wrapping the method in a property won't work (since a parameter is required), the best pet is to probably create a value converter. You can use PropertyName as the binding for the column, and then in your converter you can pass that to your method, and return the value of the method.

Andy