我有XAML:的ScrollViewer和工具提示
<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(超大顏色矩形)。
所以,問題是:
雖然滾動,除了我的事件處理程序沒有爲ScrollViewer中的作品非標準事件處理程序,所以你可以看到滾動的開始顫抖。如何關閉標準事件處理程序?
即使我設置了屬性ToolTipService.SetBetweenShowDelay和ToolTipService.SetInitialShowDelay,ToolTip也無法正常工作。延遲只是第一次。 ToolTip第一次出現後立即出現。所以,當滾動工具提示一次又一次出現時,這是工作緩慢和不流暢的原因。如何處理它?
謝謝!
你的例子與這個問題並不真正相關......如何重寫,以幫助他管理滾動? – almulo
請在downvoting之前閱讀該問題。 「如何關閉標準事件處理程序?」 – Marc