views:

30

answers:

2

I am wondering if there is a way with WPF binding to set the value via binding plus tweak it.

For example I have the width of a border being set to the canvas that contains it:

Width="{Binding Width, ElementName=mainCanvas, Mode=Default}"

Because I am doing a border with rounded corners. the Canvas.Top and Canvas.Left for the border are both set to -5. This makes the border end 5 too soon (really 10 too soon with the rounded corners on the other side).

Is there a way to do something similar to this:

Width="{Binding Width, ElementName=mainCanvas, Mode=Default} + 5"
+2  A: 

Either write your own IValueConverter that does that, and specify it in the binding, or use some of the existing generic ones that allow you to embed expressions directly into XAML - e.g. PyBinding.

Pavel Minaev
PyBinding is unreleased code. There is no download for it that I could find (though it looked really useful).
Vaccano
+1  A: 

Creating a ValueConverter would work. See this video tutorial: http://windowsclient.net/learn/video.aspx?v=26730

You may also look into using the Margin property.

CodeChef