tags:

views:

22

answers:

2

does xaml allow modification of bound value? like: width="{Binding Elementname="lstMine", Path=Width}" -100 ? so that i can have a relative value.

+1  A: 

use Converter for these purpose

Kishore Kumar
+1  A: 

You can use converters for this purpose, and my WPF Converters library includes an ExpressionConverter that allows you to do exactly that:

Width="{Binding Width, ElementName=lstMine, Converter={con:ExpressionConverter {}{0}-100}}"

HTH,
Kent

Kent Boogaart
can you please explain this part: {}{0}-100}I came to know about this method after reading your answer and browsed Google to find: http://www.thejoyofcode.com/WPF_Quick_Tip_Converters_as_MarkupExtensions.aspxis it the same?
Sarath
@Sarath: the link you provided is to a converter with a very specific purpose: multiplication. The expression converter I provided takes pretty much any C# expression and evaluates it. For example, you could bind to ActualWidth and ActualHeight in a multi-binding, and calculate their sum with `{0}+{1}`. The numbers in the curly braces are placeholders for the bound values. The leading `{}` is just an escape mechanism in XAML to tell it not to treat the subsequent '{' as a markup extension. So the actual expression is simply `{0}-100`, and the `{0}` is substituted with the `Width`.
Kent Boogaart
One last thing: you probably want `ActualWidth` rather than `Width`. The latter is not always set, and tells the layout engine how much width you'd like to allocate to the element, whereas the former is always set and contains the actual width allocated to the element, which is often different.
Kent Boogaart
Thanks a lot for the explanation Kent. I get it now :)
Sarath