我有一个Control
可见性绑定到视图模型,但也允许用户直接关闭控件。理想情况下,我想要的是CloseDialog
函数检查绑定Visibility
,如果存在,直接更新绑定值(也就是 ViewModel 的绑定值)而不是覆盖它,但我正在努力如何实际更新值本身
public void CloseDialog()
{
Control visibileObject = this;
//Check to ensure we have no binding set, if we do then update the binding expression
Binding myBinding;
#if (!SILVERLIGHT)
myBinding = BindingOperations.GetBinding(visibileObject, Control.VisibilityProperty);
#else
BindingExpression bindingExpression = visibileObject.GetBindingExpression(Control.VisibilityProperty);
myBinding = bindingExpression.ParentBinding;
#endif
if (myBinding != null)
{
//Here update binding target to be Visibility.Collapsed
}
}