假设我在 xaml 中有 RadioButton。
//...
IsChecked="{Binding A}"
//...
现在在代码的某处我有:
private bool a;
public bool A
{
get { return a; }
set { a = value; foo(); }
}
我问是因为当我将函数 foo()
添加到 setter 时,xaml 预览更改看起来很奇怪...
// 我对 C# 不是很熟悉,所以如果一般来说做这样的事情不是问题,我会尝试寻找其他原因。到目前为止,我还没有发现它是合法的,但也许对其他所有人来说都是显而易见的:)
最佳答案
foo
is checking value of A (and other values similar to A, other RadioButtons) and editing list which is not correlated to any other code so far
是的!答案是:确保这个列表不为空并且你记得初始化它!
没有 null 异常,没有任何其他消息只是 xaml 中的“奇怪”差异,并且在运行的应用程序中没有任何操作。
对不起大家:)
关于c# - 在绑定(bind)到 xaml 对象属性的属性 setter 中执行私有(private)函数是否合法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29890872/