This documentation is archived and is not being maintained.

ObjectDataProvider.MethodParameters Property

Gets the list of parameters to pass to the method.

Namespace: System.Windows.Data
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public IList MethodParameters { get; }
/** @property */
public IList get_MethodParameters ()

public function get MethodParameters () : IList


Property Value

The list of parameters to pass to the method. The default is an empty list.

You can use the MethodName property to call a method on your object and use the MethodParameters property to pass parameters to the method. You can then bind to the results of the method.

Changing this collection implicitly causes the ObjectDataProvider object to refresh. When changing multiple refresh-causing properties, the use of DeferRefresh is recommended.

The following example shows how to bind to a method using ObjectDataProvider.

In this example, TemperatureScale is a class that has a method ConvertTemp, which takes two parameters (one of double and one of the enum type TempType) and converts the given value from one temperature scale to another. In the following example, an ObjectDataProvider is used to instantiate the TemperatureScale object. The ConvertTemp method is called with two specified parameters.

  <ObjectDataProvider ObjectType="{x:Type local:TemperatureScale}"
                      MethodName="ConvertTemp" x:Key="convertTemp">

  <local:DoubleToString x:Key="doubleToString" />


Now that the method is available as a resource, you can bind to its results. In the following example, the Text property of the TextBox and the SelectedValue of the ComboBox are bound to the two parameters of the method. This allows users to specify the temperature to convert and the temperature scale to convert from. Note that BindsDirectlyToSource is set to true because we are binding to the MethodParameters property of the ObjectDataProvider instance and not properties of the object wrapped by the ObjectDataProvider (the TemperatureScale object).

The Content of the last Label updates when the user modifies the content of the TextBox or the selection of the ComboBox.

<Label Grid.Row="1" HorizontalAlignment="Right">Enter the degree to convert:</Label>
<TextBox Grid.Row="1" Grid.Column="1" Name="tb">
    <Binding Source="{StaticResource convertTemp}" Path="MethodParameters[0]"
             BindsDirectlyToSource="true" UpdateSourceTrigger="PropertyChanged"
             Converter="{StaticResource doubleToString}">
<ComboBox Grid.Row="1" Grid.Column="2" 
  SelectedValue="{Binding Source={StaticResource convertTemp},
  Path=MethodParameters[1], BindsDirectlyToSource=true}">
<Label Grid.Row="2" HorizontalAlignment="Right">Result:</Label>
<Label Content="{Binding Source={StaticResource convertTemp}}"
    Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"/>

The converter DoubleToString takes a double and turns it into a string in the Convert direction (from the binding source to binding target, which is the Text property) and converts a string to a double in the ConvertBack direction.

The InvalidationCharacterRule is a ValidationRule that checks for invalid characters. The default error template, which is a red border around the TextBox, appears to notify users when the input value is not a double value.

For the complete example, see Bind to the Results of a Method Sample.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0