I'd like set ButtonDisabled
property to false
in these conditions :
At least one property with suffix _Set1
is true and at least one property with suffix _Set2
is true
. When the conditions are no longer met set ButtonDisabled
property to true
An idea how do this ?
public bool CheckBox1_Set1 { get; set; }
public bool CheckBox2_Set1 { get; set; }
public bool CheckBox3_Set1 { get; set; }
public bool CheckBox1_Set2 { get; set; }
public bool CheckBox2_Set2 { get; set; }
public bool CheckBox3_Set2 { get; set; }
public bool ButtonDisabled { get; set; }
CodePudding user response:
This?
class Smurf
{
public Boolean CheckBox1_Set1 { get; set; }
public Boolean CheckBox2_Set1 { get; set; }
public Boolean CheckBox3_Set1 { get; set; }
public Boolean CheckBox1_Set2 { get; set; }
public Boolean CheckBox2_Set2 { get; set; }
public Boolean CheckBox3_Set2 { get; set; }
private Boolean Set1HasAtLeast1True => this.CheckBox1_Set1 || this.CheckBox2_Set1 || this.CheckBox3_Set1;
private Boolean Set2HasAtLeast1True => this.CheckBox1_Set2 || this.CheckBox2_Set2 || this.CheckBox3_Set2;
public Boolean ButtonDisabled => !( this.Set1HasAtLeast1True && Set2HasAtLeast1True );
}
Example:
void Main()
{
Smurf s = new Smurf();
s.CheckBox1_Set1 = true;
s.CheckBox2_Set2 = true;
Console.WriteLine( "Should be false: {0}", s.ButtonDisabled );
s.CheckBox1_Set1 = true;
s.CheckBox2_Set2 = false;
Console.WriteLine( "Should be true: {0}", s.ButtonDisabled );
}
Screenshot proof: