我有一个处理滚动条PreviewMouseWheel事件的类,它会缩放时间轴控件,一切都很完美,除了我必须在滚动条上方进行clr +鼠标缩放以直观地改变滚动条拇指的状态。我在时间轴控件中实现了相同的PreviewMouseWheel事件,该事件具有不同的datacontext类,可以缩放,但不会直观地更新相邻的滚动条控件。在整个窗口中处理clr +鼠标的最佳方法是什么?
public void ZoomScrollbar_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
FrameworkElement el;
el = (FrameworkElement)sender;
if (Keyboard.Modifiers == ModifierKeys.Control)
{
var newValue = InitialZoomValue;
if(e.Delta > 0)
{
newValue += 1;
}
else
{
newValue -= 1;
}
OnZoomScroll(newValue);
InitialZoomValue = newValue;
}
}
<Style x:Key="TimelineToolboxStyle" TargetType="{x:Type controls:TimelineToolbox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:TimelineToolbox}">
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition Height="*" />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<ScrollBar x:Name="ZoomScrollbar"
Grid.Row="1"
Minimum="1"
Maximum="12"
Value="{TemplateBinding InitialZoomValue}"
SmallChange="1"
Style="{DynamicResource ZoomScrollBarStyle}"
BorderThickness="9,0"
Width="22"
Margin="0"
BorderBrush="{x:Null}"
Background="Black"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:0)
通过从后面的代码调用滚动条的PreviewMouseWheel事件处理程序,我能够让鼠标滚轮与滚动条同步。
private void TimelineBand_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control)
{
TimeLineToolBoxControl.ZoomScrollbar_PreviewMouseWheel(sender, e);
}
}