Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do calculation in xaml while binding?

Tags:

binding

wpf

xaml

I can bind a label to a slider as shown below:

<Label Name="lblTest" Content="{Binding ElementName=slider1, Path=Value}"/> 

How do I bind another label to the same slider with display value of, say, 30% of the value of slider? How do I do the calculation in xaml and not in my code? Thanks.

like image 683
user763554 Avatar asked Jan 15 '12 23:01

user763554


People also ask

How does binding work 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 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 two way binding WPF?

Two way binding is used when we want to update some controls property when some other related controls property change and when source property change the actual control also updates its property.


1 Answers

You cannot do the calculation in XAML, you could however apply some converter which does it for you.

This question might be relevant: How do you change a bound value, reverse it, multiply it, subtract from it or add to it?

like image 155
H.B. Avatar answered Oct 24 '22 05:10

H.B.