Is there a way to use variable values and conditions in Binding in XAML?

Up vote 3 down vote favorite share g+ share fb share tw.

I will ask this question with reference to a specific example, I use ScaleX and ScaleY to Implement Zoom in and Zoom out in Canvas, XAML code is: And then in the code of the Zoom Out button, I write: if (zoomFactor > -3) { scale. ScaleX /= 2; scale. ScaleY /= 2; zoomFactor--; } Here zoomFactor is a private variable, that allows maximum number of times zoom out can be clicked.

My questions are: Is there a way to do this in XAML, i.e. Is there a way to define binding or trigger, or write a converter in a way that a condition based on the value of a variable is applied, and value of a variable is also updated? Also when the value of zoomFactor is -3 or 3, can the Zoom Out or Zoom In button be disabled in XAML?

Or more simply, can a button be disabled/enabled in XAML based on the value of a certain variable? If yes, how? .net wpf xaml data-binding wpf-controls link|improve this question asked Dec 27 '11 at 13:55SpeedBirdNine1,4061415 100% accept rate.

Lots of questions here: Yes, yes and yes. Bind ScaleX and ScaleY to zoomFactor, then use an IValueConverter that implements the logic you provided: public class ZoomConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization. CultureInfo culture) { double zoomFactor = (Double)value; if (zoomFactor > -3) { return 1 / 2; } return 1; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.

CultureInfo culture) { throw new NotImplementedException(); } } For the second question, take a look at DataTriggers (they must be set in a Style).

Awesome! Thank you! – SpeedBirdNine Dec 27 '11 at 14:08.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions