首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ScrollViewer和ToolTip

ScrollViewer和ToolTip
EN

Stack Overflow用户
提问于 2015-06-22 00:45:33
回答 2查看 1.4K关注 0票数 2

我有xaml:

代码语言:javascript
运行
AI代码解释
复制
<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>

以及它的代码:

代码语言:javascript
运行
AI代码解释
复制
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 (超大颜色矩形)。

因此,问题是:

  1. 在滚动时,除了我的连环画外,还有标准的连环画,用于滚动查看器的作品,所以你可以看到滚动开始时的抖动。怎样才能把标准灯关掉呢?
  2. 即使我设置了属性ToolTipService.SetBetweenShowDelay和ToolTipService.SetInitialShowDelay,ToolTip也不像我预期的那样工作。延迟只在第一次起作用。第一次出现后,ToolTip显得神采奕奕。因此,当滚动ToolTip一次又一次出现的时候,这就是工作缓慢和不顺畅的原因。怎么处理呢?

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2015-06-22 02:40:13

  1. 在您的e.Handled = true事件处理程序中使用svViewer_MouseWheel,指定要处理该事件,而不是让ScrollViewer处理它。
  2. 对这件事一无所知。我想它应该可以工作,尽管您只设置了1秒的延迟,这并不比默认值(0.4秒)长多少。
票数 0
EN

Stack Overflow用户

发布于 2015-06-22 01:26:47

为了浪费旧的均衡器,您必须为WPF TextBox创建一个带有覆盖事件的自定义控件,如本例所示。

代码语言:javascript
运行
AI代码解释
复制
class TextBoxA : TextBox
{
    protected override void OnTouchUp(System.Windows.Input.TouchEventArgs e)
    {
        base.OnTouchUp(e);
    }
}

简单地用新的代替你以前的控制。应该行得通。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30975548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档