次の点で助けが必要です: スライダー スナップを 0.5 にしたいのですが、非線形スケールのために Ticks DoubleCollection を使用しているため、TickFrequency プロパティを使用できません。実際には、ティックを使用して、次のような数字でカスタム ティック バーを描画しています。
public class NumberedTickBar : TickBar
{
protected override void OnRender(DrawingContext dc)
{
string text;
FormattedText formattedText;
int i;
double step;
double minStep = this.ActualHeight / (this.Maximum - this.Minimum);
double currentPosition = 0;
// Draw each tick text
for (i = 0; i < this.Ticks.Count; i++)
{
if (i == 0) step = i;
else step = this.Ticks[i] - this.Ticks[i - 1];
currentPosition += step * minStep;
text = "-" + this.Ticks[i].ToString();
formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Tahoma"), 10, Brushes.DimGray);
dc.DrawText(formattedText, new Point(22, base.ActualHeight - currentPosition));
}
}
}
私のスライダーの定義は次のとおりです。
<Slider Name="SomeSlider" Orientation="Vertical" Style="{DynamicResource MySliderStyle}"
Focusable="False" Value="{Binding Path=SomeProp, Mode=OneWay}"
Maximum="35" TickPlacement="TopLeft" Minimum="8" AutoToolTipPlacement="TopLeft" AutoToolTipPrecision="1"
MinHeight="80" Ticks="8,15,20,25,30,35"
ValueChanged="SomeSlider_ValueChanged"/>
大邸宅ができるように、スライダーの値は依存関係プロパティにバインドされ、次のようなことをしようとすると:
private void SLAlowCooling_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
(sender as Slider).Value = Math.Round(e.NewValue * 2, 0) / 2;
}
スライダーは操作するとうまく機能しますが、SomeProp を変更するとバインディングが機能しません。イベント処理バインディングがなくても問題なく動作します。