我正在开发一个带有进度矩形的滑块[见图]。此代码不适用于动态设置宽度
public class AudioSlider : Slider, INotifyPropertyChanged {
public AudioSlider() {
DefaultStyleKey = typeof(AudioSlider);
}
#region PropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name) {
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(name));
}
#endregion
private double _trwidth;
public double TrackProgressWidth {
get { return _trwidth; }
set {
_trwidth = value; OnPropertyChanged("TrackProgressWidth");
}
}
...
xml。默认样式...
<Rectangle x:Name="HorizontalFillLoaded" Height="12" MaxWidth="{Binding TrackProgressWidthMax,ElementName=audio}" Width="{Binding TrackProgressWidth,ElementName=audio}" IsHitTestVisible="False" Grid.Column="1" Fill="Black" Margin="0,0,0,28" />
……
我需要改变“HorizontalFillLoaded”的宽度,比如
var t=new AudioSlider();
t.SetDownloadedProgress(50);//50%