사용자가 끌기를 멈 추면 슬라이더를 0으로 되돌리고 싶습니다. 이만큼 내 DependencyProperty에 ZSpeed 슬라이더 값을 결합하지 않는 한 작동슬라이더가 0으로 돌아갑니다.
<Window x:Class="CenteredSliderTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<!--Value="{Binding ZSpeed}"-->
<Slider DockPanel.Dock="Left"
x:Name="ZSlider"
Minimum="-100" Maximum="100"
SelectionStart="-20" SelectionEnd="20"
Orientation="Vertical"
TickFrequency="10"
TickPlacement="TopLeft"
AutoToolTipPlacement="TopLeft"
AutoToolTipPrecision="2"
LargeChange="10"
SmallChange="1"
IsDirectionReversed="True"
Focusable="False"
>
<Slider.Triggers>
<EventTrigger RoutedEvent="LostMouseCapture" SourceName="ZSlider">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ZSlider"
Storyboard.TargetProperty="Value"
From="{Binding Value, ElementName=ZSlider}"
To="0.0"
Duration="0:0:1.5"
FillBehavior="Stop"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Slider.Triggers>
</Slider>
<TextBlock Text="{Binding ZSpeed}" />
</DockPanel>
</Window>
:
지금까지 나는이 있습니다.
이렇게하면 슬라이더가 원래 값으로 돌아가고 두 번째 시도에서는 슬라이더를 더 이상 끌 수 없습니다.
애니메이션을 얻으려면 슬라이더뿐만 아니라 ZSpeed 속성도 수정하면됩니다 (xaml에서 더 좋음). MainWindow를에
편집
코드 :
public partial class MainWindow : Window
{
public double ZSpeed
{
get { return (double)GetValue(ZSpeedProperty); }
set { SetValue(ZSpeedProperty, value); }
}
// Using a DependencyProperty as the backing store for ZSpeed. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ZSpeedProperty =
DependencyProperty.Register("ZSpeed", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0.0));
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
Binding binding = new Binding("Value") { Source = ZSlider };
this.SetBinding(ZSpeedProperty, binding);
}
}
바인딩 도움말에 'OneWay'가 지정되어 있습니까? – paul
예, 그렇지만 ZSpeed가 그에 따라 설정되지 않았습니다. – MTR
왜 anymation을'ZSpeed'에 바인딩하지 않습니까? 슬라이더가 자동으로 업데이트됩니다. 면책 조항 : 저는 애니메이션 작업을 해 본적이 없으므로 이것이 제대로 작동하는지 모르겠습니다. –