私はここに、スライダーの値を取得することができますC#WPFのSliderの値を取得してバインドする方法は?
public void TheSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
int k = (int)TheSlider.Value;
Debug.WriteLine(k);
}
この部分では、私は値を取得カントので、私はそれを使用するカント:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_runtime.NuiCamera.ElevationAngle = (int)TheSlider.Value;
}
これはXAMLでスライダーコードです:
<Slider x:Name="TheSlider"
DockPanel.Dock="Left"
Orientation="Horizontal"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
Minimum="-27"
Maximum="27"
Cursor="Hand"
IsSnapToTickEnabled="True"
Margin="322,392,329,87" ValueChanged="TheSlider_ValueChanged" Width="144" />
ここで問題は何ですか?私を助けてくれますか?
UPDATE:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
System.Windows.Data.Binding b = new System.Windows.Data.Binding();
b.ElementName = "TheSlider";
b.Path = new PropertyPath("Value");
SetBinding(ElevationAngleProperty, b);
}
public int ElevationAngle
{
get { return _runtime.NuiCamera.ElevationAngle; }
set { _runtime.NuiCamera.ElevationAngle = value; OnPropertyChanged("ElevationAngle"); }
}
public DependencyProperty ElevationAngleProperty { get; set; }
まあ... WPFで知っているように、あなたは本当にバインディングではありません。今のところ、TheSlider_ValueChangedメソッド内でElevationAngleを変更することができます。 – NestorArturo
私はそれをしましたが、メソッドTheSlider_ValueChangedの中でそれを行うと、アプリケーションの実行が停止します。 ElevationAngleはWindow_Loaded内にある必要があります。 :S – Samet
それは本当に奇妙に聞こえる。エラーが報告されましたか? – NestorArturo