0

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.

4

1 回答 1

0

由于将方法包装在属性中是行不通的(因为需要参数),所以最好的方法是创建一个值转换器。您可以将PropertyName其用作列的绑定,然后在您的转换器中,您可以将其传递给您的方法,并返回该方法的值。

于 2009-03-21T23:38:35.690 回答