第一个滚动条表示从最小值到第二个滚动条的值,第二个滚动条表示从最小值到最大值的值。
因此,当我更改我的最大值或最小值时,我的第二个滚动条正常工作(scailing)。而且当我使用我的第一个滚动条时,我的第二个滚动条不会缩放 - 它应该如何。
当我使用第二个滚动条并将当前值设置为低于第一个滚动条的值时,会出现问题。当我的第二个滚动条值变得低于(第一个滚动条的最大值)时,是否有可能以某种方式更改第一个滚动条值。以某种方式同步第一个滚动条的最大值和第二个滚动条的当前值,所以当我设置第二个滚动条值低于第一个的最大值时,它也会改变第一个滚动条的最大值。
<ScrollBar Name="FirstScrollBar"
Minimum="{Binding Path=startValue}"
Maximum="{Binding Path=yellowFinishTag, Mode=TwoWay}"
Value="{Binding Path=redFinishTag, Mode=TwoWay}"/>
<ScrollBar Name="SecondScrollBar"
Minimum="{Binding Path=startValue, Mode=TwoWay}"
Maximum="{Binding Path=endValue, Mode=TwoWay}"
Value="{Binding Path=yellowFinishTag, Mode=TwoWay}"/>
型号:
public class Scale
{
public float startValue { get; set; }
public float endValue { get; set; }
public float redFinishTag { get; set; }
public float yellowFinishTag { get; set; }
//Marks
public float markFromValue { get; set; }
public float markToValue { get; set; }
public Scale()
{
}
public ScaleDTO(float startValue, float endValue, float redFinishTag, float yellowFinishTag)
{
this.startValue = startValue;
this.endValue = endValue;
this.redFinishTag = redFinishTag;
this.yellowFinishTag = yellowFinishTag;
}
}
更新 我已经将MVVM方法添加到我的项目中以便修复它。 我的ScaleViewModel:
public class ScaleViewModel : INotifyPropertyChanged
{
Scale scale;
public ScaleViewModel()
{
scale = new Scale(0,100,0,0);
}
public Scale Scale
{
get
{
return scale;
}
set
{
scale = value;
}
}
public float StartValue
{
get { return scale.startValue; }
set
{
if (scale.startValue != value)
{
scale.startValue = value;
RaisePropertyChanged("StartValue");
}
}
}
public float EndValue
{
get { return scale.endValue; }
set
{
if (scale.endValue != value)
{
scale.endValue = value;
RaisePropertyChanged("EndValue");
}
}
}
public float RedFinishTag
{
get { return scale.redFinishTag; }
set
{
if (scale.redFinishTag != value)
{
scale.redFinishTag = value;
RaisePropertyChanged("RedFinishTag");
}
}
}
public float YellowFinishTag
{
get { return scale.yellowFinishTag; }
set
{
if (scale.yellowFinishTag != value)
{
scale.yellowFinishTag = value;
RaisePropertyChanged("YellowFinishTag");
}
}
}
public float MarkFromValue
{
get { return scale.markFromValue; }
set
{
if (scale.markFromValue != value)
{
scale.markFromValue = value;
RaisePropertyChanged("MarkFromValue");
}
}
}
public float MarkToValue
{
get { return scale.markToValue; }
set
{
if (scale.markToValue != value)
{
scale.markToValue = value;
RaisePropertyChanged("MarkToValue");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
// take a copy to prevent thread issues
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
当我添加这个错误的代码时,一切正常:
if (Scale.YellowFinishTag < Scale.RedFinishTag)
{
Scale.RedFinishTag = Scale.YellowFinishTag;
}