Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding to the whole data item in XAML

I'm using XAML data binding for a ListBox whose ItemSource is set to a list of TypeA object. One UI element in the ItemTemplate for the ListBox is bound to a property of TypeA as follows:

Source="{Binding PropertyName, Converter={StaticResource customConverter}}"

Now, instead of binding to a specific property, I want the UI element to be bound to the whole TypeA instance so that the custom converter can compute value from multiple properties. The question is: which binding expression I can use to achieve that?

like image 658
Buu Nguyen Avatar asked Jan 13 '11 08:01

Buu Nguyen


People also ask

How do I bind data in XAML?

Data binding is a mechanism in XAML applications that provides a simple and easy way for Windows Runtime Apps using partial classes to display and interact with data. The management of data is entirely separated from the way the data is displayed in this mechanism.

How do you bind data?

Select the first TextBox. Expand "Other data source" ---> "Project data source" --> "AdventureWorksdataset" --> "Employee" --> "EmloyeeId". Select the second TextBox. Expand the DataBinding property then select "Text" ---> "Employee Binding source" then select column(National ID) from the list.

How does data binding work in WPF?

Data binding is a mechanism in WPF applications that provides a simple and easy way for Windows Runtime apps to display and interact with data. In this mechanism, the management of data is entirely separated from the way data. Data binding allows the flow of data between UI elements and data object on user interface.

What is OneWayToSource data binding in WPF?

OneWayToSource: The Source property will change if the target property is changed. If the user changes the TextProperty , the UserName property will take up the changed value. This again is of intermediate cost as the binding system watches only Target for changes.


2 Answers

Youn include no path at all to do that:-

 Source="{Binding Converter={StaticResource customConverter}}
like image 153
AnthonyWJones Avatar answered Nov 04 '22 19:11

AnthonyWJones


Have you tried this:

Source="{Binding ., Converter={StaticResource customConverter}}"
like image 37
TerenceJackson Avatar answered Nov 04 '22 18:11

TerenceJackson