Q:

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

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:
<Canvas>
    <Canvas.LayoutTransform>
        <ScaleTransform x:Name="scale"  ScaleX="1" ScaleY="1" />
    </Canvas.LayoutTransform>
</Canvas>

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?

A:

Lots of questions here: Yes, yes and yes.
Bind ScaleX and ScaleY to zoomFactor, then use an IValueConverter that implements the logic you provided:
    <Canvas>
        <Canvas.LayoutTransform>
            <ScaleTransform x:Name="scale"  
ScaleX="{Binding zoomFactor, Converter={StaticResource ZoomConverter}" 
ScaleY="{Binding ScaleX RelativeSource={RelativeSource Mode=Self}}" />
        </Canvas.LayoutTransform>
    </Canvas>

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).

