这里的问题似乎是绑定最初评估为null
,因此不会触发评估和状态更改所需的更改通知。
我用以下子类修复了它:
public class FixedDataStateBehavior: DataStateBehavior
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.Loaded += (sender, routedEventArgs) =>
{
var bindingExpression = BindingOperations.GetBindingExpression(this, BindingProperty);
SetCurrentValue(BindingProperty,new object());
bindingExpression.UpdateTarget();
};
}
}
并像这样使用它:
<FixedDataStateBehavior Binding="{Binding SelectedCamera}" Value="{x:Null}" TrueState="CameraSettingsUnselected" FalseState="CameraSettingsSelected"/>