Click here to Skip to main content
15,923,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Is it possible to do addition in wpf binding path?

Something like this:
Width="{Binding ElementName=Grid1, Path=ActualWidth + 20}"


[edit]Tags only - OriginalGriff[/edit]
Posted
Updated 2-Nov-10 1:34am
v4
Comments
Dalek Dave 2-Nov-10 7:36am    
Edited for Readability.

1 solution

Your best bet would be to use a converter something like this :

C#
[ValueConversion(typeof(double), typeof(double))]
    class AddWidthConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double currentValue = (double)value;
            return currentValue + 70;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Then declare your converter in your Window.Resources and then use it in your xaml like this :

Width="{Binding ElementName=txtTest, Path=ActualWidth, Converter={StaticResource AddWidth}
 
Share this answer
 
v2
Comments
Dalek Dave 2-Nov-10 7:36am    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900