Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Style Setter Property Binding

Tags:

wpf

xaml

This works.

     <Setter Property="Width" Value="300" />
     <Setter Property="Height" Value="300" />

But When I change that, does not work.

    <Setter Property="Width" Value="{Binding ImageSize, Mode=TwoWay}" />
    <Setter Property="Height" Value="{Binding ImageSize, Mode=TwoWay}" />

and declare

    private Int32 imageSize;
    public Int32 ImageSize
    {
        get { return imageSize; }
        set
        {
            imageSize = value;
            NotifyPropertyChanged("ImageSize");
        }
    }

What is wrong?

like image 682
mozkarakoc Avatar asked Jun 02 '13 17:06

mozkarakoc


1 Answers

The most likely cause is a problem with the binding, and specifically the DataContext. I'd recommend looking in the Output window for binding errors (they will not be raised as standard exceptions, but will be captured in the Output window for debugging purposes). The binding errors should point you in the right direction as far as what WPF recognizes as the DataContext.

like image 87
Brian S Avatar answered Nov 07 '22 12:11

Brian S