--- title: "How to: Bind to a Method" description: Follow this example to find out how to bind to the method of an object in the Windows Presentation Foundation (WPF). ms.date: "03/30/2017" helpviewer_keywords: - "data binding [WPF], binding to methods using ObjectDataProvider" - "binding [WPF], to methods" - "methods [WPF], binding to" ms.assetid: 5f55e71e-2182-42a0-88d1-700cc1427a7a --- # How to: Bind to a Method The following example shows how to bind to a method using . ## Example 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 is used to instantiate the `TemperatureScale` object. The `ConvertTemp` method is called with two specified parameters. [!code-xaml[BindToMethod#WindowResources](~/samples/snippets/csharp/VS_Snippets_Wpf/BindToMethod/CS/Window1.xaml#windowresources)] Now that the method is available as a resource, you can bind to its results. In the following example, the property of the and the of the 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 is set to `true` because we are binding to the property of the instance and not properties of the object wrapped by the (the `TemperatureScale` object). The of the last updates when the user modifies the content of the or the selection of the . [!code-xaml[BindToMethod#UI](~/samples/snippets/csharp/VS_Snippets_Wpf/BindToMethod/CS/Window1.xaml#ui)] The converter `DoubleToString` takes a double and turns it into a string in the direction (from the binding source to binding target, which is the property) and converts a `string` to a `double` in the direction. The `InvalidationCharacterRule` is a that checks for invalid characters. The default error template, which is a red border around the , appears to notify users when the input value is not a double value. ## See also - [How-to Topics](data-binding-how-to-topics.md) - [Bind to an Enumeration](how-to-bind-to-an-enumeration.md)