我有以下代码:
@Override
public void start(Stage stage) throws Exception {
TextField textField1=new TextField();
SimpleStringProperty property=new SimpleStringProperty("Initial Value");
textField1.textProperty().bindBidirectional(property);
Button but1=new Button("New value");
Button but2=new Button("Unbind");
but1.setOnAction((event)->{
property.set("New Value");
});
but2.setOnAction((event)->{
//THIS LINE
});
VBox vbox=new VBox();
vbox.getChildren().addAll(textField1,but1,but2);
Scene scene=new Scene(vbox, 200, 400);
stage.setScene(scene);
stage.show();
}
Run Code Online (Sandbox Code Playgroud)
问题是如果我THIS LINE替换为
textField1.textProperty().unbind();
Run Code Online (Sandbox Code Playgroud)
解除绑定不起作用。但如果我替换为
textField1.textProperty().unbindBidirectional(property);
Run Code Online (Sandbox Code Playgroud)
解绑作品。
我有很多房产,但不想保留它们的参考资料。是否可以从 textField1 或 textField1.textProperty() 获取属性?或者是否可以在不参考的情况下以其他方式解除绑定property
据我所知,没有办法做到这一点。您可以将一个属性双向绑定到任意数量的属性。即使您可以检索textField1.textProperty()双向绑定的属性列表(我很确定没有办法做到这一点),您如何知道要取消绑定哪一个?
“我有很多房产,但不想保留它们的参考资料。” 只是建议您需要重新考虑您的设计 - 您实际上应该只绑定到模型中的事物,您必须保留对这些事物的引用。
| 归档时间: |
|
| 查看次数: |
2752 次 |
| 最近记录: |