我有xaml:
<Grid>
<ScrollViewer x:Name="svViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden" Grid.Column="0" Grid.Row="0">
<Border>
<ItemsControl x:Name="svItemControl" VerticalAlignment="Stretch" MouseWheel="svViewer_MouseWheel">
</ItemsControl>
</Border>
</ScrollViewer>
</Grid>
以及它的代码:
public partial class MainWindow : Window
{
double Friction;
private DispatcherTimer animationTimer = new DispatcherTimer();
double scrollVelocity;
double scrollOffset;
const double c_vel_colors = 8;
public MainWindow()
{
InitializeComponent();
Friction = 0.9;
InitializeComponent();
loadContent();
animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 5);
animationTimer.Tick += new EventHandler(HandleWorldTimerTick);
animationTimer.Start();
}
private void HandleWorldTimerTick(object sender, EventArgs e)
{
if (Math.Abs(scrollVelocity) > 1)
{
svViewer.ScrollToVerticalOffset(scrollOffset);
scrollOffset += scrollVelocity;
scrollVelocity *= Friction;
}
}
public void svViewer_MouseWheel(object sender, MouseWheelEventArgs e)
{
scrollVelocity = (e.Delta > 0) ? -1 * (c_vel_colors) : (c_vel_colors);
scrollOffset = svViewer.VerticalOffset + scrollVelocity;
}
void loadContent()
{
StackPanel sp2 = new StackPanel();
sp2.Orientation = Orientation.Vertical;
Rectangle[] rc = new Rectangle[50];
Random rnd = new Random();
SolidColorBrush _brush;
for (int i = 0; i < rc.Length; i++)
{
_brush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rnd.Next(0, 255), (byte)rnd.Next(0, 255), (byte)rnd.Next(0, 255)));
rc[i] = new Rectangle(); rc[i].Height = 50; rc[i].Width = 50;
rc[i].Fill = _brush;
StackPanel sp_tt_Colors = new StackPanel();
Rectangle tt_Rect = new Rectangle
{
Fill = _brush,
Width = 100,
Height = 100
};
TextBlock tb = new TextBlock
{
Foreground = new SolidColorBrush(Color.FromArgb((byte)255, (byte)255, (byte)255, (byte)255)),
FontSize = 12,
Text = i.ToString()
};
sp_tt_Colors.Children.Add(tt_Rect);
sp_tt_Colors.Children.Add(tb);
ToolTip tt = new ToolTip();
ToolTipService.SetIsEnabled(rc[i], true);
ToolTipService.SetBetweenShowDelay(rc[i], 1000);
ToolTipService.SetInitialShowDelay(rc[i], 1000);
tt.Content = sp_tt_Colors;
tt.Background = new SolidColorBrush(Color.FromArgb((byte)32, (byte)10, (byte)10, (byte)245));
rc[i].ToolTip = tt;
sp2.Children.Add(rc[i]);
i++;
}
svItemControl.Items.Add(sp2);
}
}
我们的目标是用彩色矩形滚动这个列表,我有自己的MouseWheeel - ScrollViewer滚动器,在两边都很平滑。每个矩形都有自己的ToolTip (超大颜色矩形)。
因此,问题是:
谢谢!
发布于 2015-06-22 02:40:13
e.Handled = true
事件处理程序中使用svViewer_MouseWheel
,指定要处理该事件,而不是让ScrollViewer处理它。发布于 2015-06-22 01:26:47
为了浪费旧的均衡器,您必须为WPF TextBox创建一个带有覆盖事件的自定义控件,如本例所示。
class TextBoxA : TextBox
{
protected override void OnTouchUp(System.Windows.Input.TouchEventArgs e)
{
base.OnTouchUp(e);
}
}
简单地用新的代替你以前的控制。应该行得通。
https://stackoverflow.com/questions/30975548
复制相似问题