我有2个文本字段代表Xmin
和Xmax
四边形的值,此值初始化的构造函数为myClass
。更新2个字段取决于每个其他值,但每个也取决于其他属性值
我也有2个领域,Delta
和Counter
,这取决于Xmin
和Xmax
他们必须使用公式更新:
this.Delta = (int)((this.Xmax - this.Xmin)/(this.Counter - 1));
和
this.Counter = ((this.Xmax - this.Xmin)/(this.Delta)) + 1 ;
这似乎不是什么难事,但是我想允许Delta
和Counter
更新,如果其他更改,即如果Delta
更改然后Counter
更新ES,反之亦然,这一切 考虑Xmin
和Xmax
值
这里是我有
WPF
<GroupBox Header="Values" Height="93" HorizontalAlignment="Left" Margin="4,3,0,0" Name="GBoxGridDefinition" VerticalAlignment="Top" Width="624">
<Grid>
<TextBlock Height="20" Margin="20,13,0,0" Name="TbXmin" Text="Xmin:" Width="36" />
<controls:WaterMarkNumericInput x:Name="TBXmin" Height="20" Width="89" Margin="59,9,0,0" Style="{StaticResource goStRWMNI}" Number="{Binding Path=Xmin, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True,NotifyOnValidationError=True}" IsNullAllowed="False" />
<TextBlock Height="20" Margin="154,10,0,0" Name="TbXmax" Text="Xmax:" Width="36" />
<controls:WaterMarkNumericInput x:Name="TBXmax" Height="20" Width="89" Margin="198,10,0,0" Style="{StaticResource goStRWMNI}" Number="{Binding Path=Xmax, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True,NotifyOnValidationError=True}" IsNullAllowed="False" />
</Grid>
</GroupBox>
<GroupBox Header="Dynamic changes" Height="77" HorizontalAlignment="Left" Margin="5,98,0,0" Name="GbxNodes" VerticalAlignment="Top" Width="463" >
<Grid>
<TextBlock Height="20" Margin="28,7,0,0" Name="TbDelta" Text="Delta X:" Width="48" />
<controls:WaterMarkNumericInput x:Name="TBDelta" Height="20" Width="119" IsNegativeSignAllowed="False" Margin="90,4,0,0" Style="{StaticResource goStRWMNI}" Number="{Binding Path=Delta, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsNullAllowed="False"/>
<TextBlock Height="20" Margin="223,6,0,0" Name="TbCounter" Text="XX' nodes counter:" Width="109" />
<controls:WaterMarkNumericInput x:Name="TBCounter" IsEnabled="False" Height="20" Width="111" Margin="330,4,0,0" Style="{StaticResource goStRWMNI}" Number="{Binding Path=Counter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True,NotifyOnValidationError=True}" IsNullAllowed="False" />
</Grid>
</GroupBox>
我已经加入绑定和性能变化,在开始的时候Counter = 100
,但我不知道如何更新Counter
当Delta
更改并反之亦然
这里是c#代码
public partial class myClass : UserControl
{
double gnXmin, gnXmax, gnCounter;
int gnDelta;
public event PropertyChangedEventHandler PropertyChanged;
public double Xmin
{
get { return gnXmin; }
set { gnXmin = value; OnPropertyChanged("Xmin"); }
}
public double Xmax
{
get { return gnXmax; }
set { gnXmax = value; OnPropertyChanged("Xmax"); }
}
public int Delta
{
get { return gnDelta; }
set { gnDelta = value; OnPropertyChanged("Delta"); }
}
public double Counter
{
get { return gnCounter; }
set { gnCounter = value; OnPropertyChanged("Counter"); }
}
public myClass(double _Xmin, double _Xmax)
{
this.Xmin = _Xmin;
this.Xmax = _Xmax;
this.Counter = 100;
this.Delta = (int)((this.Xmax - this.Xmin)/(this.Counter - 1));
}
void OnPropertyChanged(string prop)
{
if (this.PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
我怎样才能更新两个要素或结合他们,让其他的时候被修改,但考虑Xmin
和Xmax
性质每一个被修改?
我试图把更新代码中的getter和setter,但作为一个字段取决于Xmin
和Xmax
我得到一个无限循环的例外......