Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Mathematical Operations in XAML

Is is possible to do basic mathematical operations like addition, division etc. in XAML?

For example, I want to set the height of a button to {Binding ElementName=MW,Path=Height}/2.

like image 312
Elmo Avatar asked Jan 07 '12 19:01

Elmo


4 Answers

Take a look at Arithmetic operations in Xaml for simple operations

and

for more complex evaluation look at Impossible WPF Part 2: Binding Expressions

like image 165
Haris Hasan Avatar answered Nov 20 '22 08:11

Haris Hasan


To answer your question: No, it is not possible.

like image 26
H.B. Avatar answered Nov 20 '22 09:11

H.B.


My advice would be to create a value converter and apply them using bindings, for any mathematical operations you want to perform. The view is definitely not the place to perform mathematical operations, you want to have that concern separated and isolated in a different class, so that it is easier to debug and maintain.

like image 1
Murven Avatar answered Nov 20 '22 08:11

Murven


Not possible without using a converter or a view model that does the conversion for you. For a generic converter, see ExpressionConverter in my WPF Converters project.

like image 1
Kent Boogaart Avatar answered Nov 20 '22 07:11

Kent Boogaart