我想进行绑定,当按下buttonA
时(将值从false更改为true)lightIsTurnedOn
转动true
(buttonB的值的独立值),当另一个{{1}时按下(将值从false更改为true)buttonB
变为lightIsTurnedOn
(buttonA的值的独立值)。
是否可以使用绑定来处理它?
false
答案 0 :(得分:0)
ToggleButton
s似乎是一个完美的任务:
ToggleButton buttonA = new ToggleButton("A");
ToggleButton buttonB = new ToggleButton("B");
Label label = new Label();
label.textProperty().bind(buttonA.selectedProperty().or(buttonB.selectedProperty()).asString());
Label
的文字将在"true"
中至少有一个“开启”时更改为ToggleButton
,如果两个"false"
都更改为 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:HiddenField ID="currTab" runat="server" />
<asp:Panel ID="tabPanel" runat="server">
<ul>
<li><a href="#Panel1" style="padding-left:8px;"><span>General Feedback</span></a></li>
<li><a href="#Panel2" style="padding-left:6px;"><span>New Requirements</span></a></li>
<li><a href="#Panel3" style="padding-left:8px;"><span>My Feedback</span></a></li>
</ul>
<%-- general feedback tab--%>
<asp:Panel ID="Panel1" runat="server">
<div class="tabcaption">General Feedback</div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<table class="general">
<tr>
<td style="padding-left:22px;">1.Did you find the information you were looking for?</td>
</tr>
<tr>
<td style="padding-left:30px;"> if no please explain why?</td>
</tr>
<tr >
<td style="padding-left:28px;">
<div id="RadioDiv1">
<asp:RadioButtonList ID="radiolist1" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="radio1">
<asp:ListItem Value="yes">Yes </asp:ListItem>
<asp:ListItem Value="no">No</asp:ListItem>
</asp:RadioButtonList>
</div>
</td>
</tr>
<tr >
<td >
<div id="info" style="padding-left:64px;">Please Explain:
<asp:TextBox ID="infodesc" runat="server" CssClass="textb" TextMode="MultiLine"></asp:TextBox>
</div>
</td>
</tr>
<tr>
<td style="padding-left:22px;"> 2.Did the portal meet your need/ answer your questions?</td>
</tr>
<tr>
<td style="padding-left:30px;"> if no please explain why?</td>
</tr>
<tr >
<td style="padding-left:28px;">
<div id="RadioDiv2">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="radio1">
<asp:ListItem Value="yes">Yes </asp:ListItem>
<asp:ListItem Value="no">No</asp:ListItem>
</asp:RadioButtonList>
</div>
</td>
</tr>
<tr >
<td >
<div id="port" style="padding-left:64px;">Please Explain:
<asp:TextBox ID="portdesc" runat="server" CssClass="textb" TextMode="MultiLine"></asp:TextBox>
</div>
</td>
</tr>
<tr><td style="padding-left:22px;">3.Please rate these</td>
</tr>
<tr>
<td style="padding-left:32px;">a.GUI</td>
<td>
<asp:Rating ID="Rating1" runat="server" BehaviorID="RatingBehavior1" CssClass="textb"
MaxRating="5"
StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar1"
FilledStarCssClass="filledRatingStar1"
EmptyStarCssClass="emptyRatingStar1"
OnChanged="ThaiRating_Changed"
Style="float: left;" />
</td>
</tr>
<tr>
<td style="padding-left:32px;">b.Correctness of content</td>
<td>
<asp:Rating ID="Rating2" runat="server" BehaviorID="RatingBehavior2" CssClass="textb"
MaxRating="5"
StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar1"
FilledStarCssClass="filledRatingStar1"
EmptyStarCssClass="emptyRatingStar1"
OnChanged="ThaiRating_Changed"
Style="float: left;" />
</td>
</tr>
<tr>
<td style="padding-left:32px;">c.Existing functionality</td>
<td>
<asp:Rating ID="Rating3" runat="server" BehaviorID="RatingBehavior3" CssClass="textb"
MaxRating="5"
StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar1"
FilledStarCssClass="filledRatingStar1"
EmptyStarCssClass="emptyRatingStar1"
OnChanged="ThaiRating_Changed"
Style="float: left;" />
</td>
</tr>
<tr><td style="padding-left:22px;">4.Please give a feedback</td></tr>
<tr>
<td style="padding-left:34px;">
<asp:TextBox ID="msg" runat="server" CssClass="textb" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:22px;">5.Do you have any document/image/screenshot/slide for the new requirement reference? if yes,please upload(max 2MB)</td>
</tr>
<tr>
<td>
<asp:FileUpload ID="fileupload1" runat="server" CssClass="textb" onchange="validateFileSize();"/>
<asp:Label ID="lblMessage" Text=" " runat="server" style="color:Red;"/>
<div id="dvMsg" style="color:Red; width:195px;display:none;" >
File size is greater than 2mb </div>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" OnClick="btnUpload_Click" Text="Save and Continue" CssClass="btn" AutoPostback = "false"/>
<%-- <asp:Button ID="Button4" runat="server" Text="Save and Continue" CssClass="btn" OnClick="Button4_Click" />--%>
</asp:Panel>
<%-- new requirements tab--%>
<asp:Panel ID="Panel2" runat="server">
<div class="tabcaption">New requirements</div>
<table class="newrq">
<tr>
<td style="padding-left:22px;"> 1.What are your new Requirements? Please Explain: </td>
</tr>
<tr>
<td style="padding-left:53px;">
<asp:TextBox ID="newrequire" runat="server" CssClass="textb" TextMode="MultiLine" ></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:22px;">2.Do you require any new functions ?</td>
</tr>
<tr >
<td style="padding-left:28px;">
<div id="RadioDiv">
<asp:RadioButtonList ID="newfunc" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="radio1">
<asp:ListItem Value="yes">Yes </asp:ListItem>
<asp:ListItem Value="no">No</asp:ListItem>
</asp:RadioButtonList>
</div>
</td>
</tr>
<tr >
<%-- <td style="padding-left:28px;width:200px;margin-left:-220px;">Functions List</td>--%>
<td>
<div id="fundiv" style="padding-left:64px;">
Functions List:
<asp:DropDownList ID="funlist" runat="server">
<asp:ListItem runat="server" Value="no">--Select--</asp:ListItem>
<asp:ListItem runat="server" Value="yes">Reports</asp:ListItem>
<asp:ListItem runat="server" Value="yes">Charts</asp:ListItem>
<asp:ListItem runat="server" Value="yes">Graphs</asp:ListItem>
<asp:ListItem runat="server" Value="yes">Analysis</asp:ListItem>
<asp:ListItem runat="server" Value="yes">Others</asp:ListItem>
</asp:DropDownList>
</div>
</td>
</tr>
<tr><%-- <td style="padding-left:28px;width:200px;margin-left:-220px;">Please Explain</td>--%>
<td>
<div id="expdiv" style="padding-left:64px;">
Please Explain:
<asp:TextBox ID="fundesc" runat="server" CssClass="textb" TextMode="MultiLine"></asp:TextBox>
<a alt="Reports" class="tooltipDemo" href="#">
<asp:Image ID="Image3" runat="server" Height="25px" ImageUrl="images/tooltip.jpg" style="margin-top: -49px;" Width="25px" />
</a>
</div>
</td>
</tr>
<tr>
<td style="padding-left:22px;">3.What will be the input data for the requirement?</td>
</tr>
<tr>
<td style="width:385px;padding-left:53px;">
<asp:TextBox ID="inpt" runat="server" CssClass="textb" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:22px;">4.What should be the output data for the requirement?</td>
</tr>
<tr>
<td style="width:385px;padding-left:53px;">
<asp:TextBox ID="oupt" runat="server" CssClass="textb" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-left:22px;">5.Do you have any document/image/screenshot/slide for the new requirement reference? if yes,please upload(max 2MB)</td>
</tr>
<tr>
<td>
<asp:FileUpload ID="fileupload2" runat="server" CssClass="textb" onchange="validateFileSize1();"/>
<asp:Label ID="Label1" runat="server" ></asp:Label>
<div id="dvMsg1" style="color:Red; width:195px;display:none;" >
File size is greater than 2mb </div>
</td>
</tr>
</table>
<asp:Button ID="Button2" runat="server" Text="Save" onclick="btnUpload_Click1" CssClass="btn" />
</asp:Panel>
<%-- My feedback tab--%>
<asp:Panel ID="Panel3" runat="server">
<div class="tabcaption"> </div>
<div style="overflow:auto;">General Feedback
<asp:GridView ID="dataGridView2" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
AutoGenerateColumns="true" OnPageIndexChanging="datagrid_PageIndexChangingimg">
</asp:GridView></div>
<br /><br />
<div style="overflow:auto;">
New Requirements
<asp:GridView ID="dataGridView3" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
AutoGenerateColumns="true" OnPageIndexChanging="datagrid_PageIndexChangingimg1">
</asp:GridView></div>
</asp:Panel>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
</div>
被“关掉”。
答案 1 :(得分:0)
不能用绑定做到这一点。绑定的值由computeValue
方法计算(至少不在某处存储其他信息)。此方法不会获取任何参数。它根本没有关于哪个依赖项最后失效的任何信息。
因此,无法区分以下修改序列
buttonA pressed
buttonB pressed
和
buttonB pressed
buttonA pressed
但结果是lightIsTurnedOn
为false
/ true
。
然而,当然这样的事情是可能的,即使只是向设置值的属性添加监听器也是可取的。
@Override
public void start(Stage primaryStage) {
ToggleButton buttonA = new ToggleButton("A");
ToggleButton buttonB = new ToggleButton("B");
Circle light = new Circle(30, Color.YELLOW);
light.visibleProperty().bind(new BooleanBinding() {
boolean lastA = false;
boolean lastB = false;
{
bind(buttonA.selectedProperty(), buttonB.selectedProperty());
}
boolean value = false;
@Override
protected boolean computeValue() {
boolean a = buttonA.isSelected();
boolean b = buttonB.isSelected();
if (lastA != a && a) {
value = true;
}
if (lastB != b && b) {
value = false;
}
lastA = a;
lastB = b;
return value;
}
});
HBox root = new HBox(buttonA, buttonB, light);
root.setAlignment(Pos.CENTER);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}