WPF - 样式设置器属性绑定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16885637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF - Style Setter Property Binding
提问by mozkarakoc
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?
怎么了?
回答by Brian S
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.
最可能的原因是绑定问题,特别是DataContext. 我建议在输出窗口中查看绑定错误(它们不会作为标准异常引发,但会在输出窗口中捕获以进行调试)。就 WPF 识别为 DataContext.

