gpt4 book ai didi

Silverlight 3 数据网格 : How to add scrollwheel support?

转载 作者:行者123 更新时间:2023-12-04 06:58:16 25 4
gpt4 key购买 nike

Silverlight 3 工具包中的数据网格没有响应滚轮(鼠标滚轮)。有没有办法获得滚轮的支持?

最佳答案

以下是我正在使用的行为。下面是如何将它附加到 xaml 中的数据网格。

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Automation.Peers;
using System.Windows.Interactivity;
using System.Windows.Automation.Provider;
using System.Windows.Automation;
using System.Windows.Data;

namespace GLS.Gui.Helper.Behaviors
{
public class MouseWheelScrollBehavior : Behavior<Control>
{
/// <summary>
/// Gets or sets the peer.
/// </summary>
/// <value>The peer.</value>
private AutomationPeer Peer { get; set; }

/// <summary>
/// Called after the behavior is attached to an AssociatedObject.
/// </summary>
/// <remarks>Override this to hook up functionality to the AssociatedObject.</remarks>
protected override void OnAttached()
{
this.Peer = FrameworkElementAutomationPeer.FromElement(this.AssociatedObject);

if (this.Peer == null)
this.Peer = FrameworkElementAutomationPeer.CreatePeerForElement(this.AssociatedObject);

this.AssociatedObject.MouseWheel += new MouseWheelEventHandler(AssociatedObject_MouseWheel);
base.OnAttached();
}

/// <summary>
/// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.
/// </summary>
/// <remarks>Override this to unhook functionality from the AssociatedObject.</remarks>
protected override void OnDetaching()
{
this.AssociatedObject.MouseWheel -= new MouseWheelEventHandler(AssociatedObject_MouseWheel);
base.OnDetaching();
}

/// <summary>
/// Handles the MouseWheel event of the AssociatedObject control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Input.MouseWheelEventArgs"/> instance containing the event data.</param>
void AssociatedObject_MouseWheel(object sender, MouseWheelEventArgs e)
{
//Do not handle already handled events
if (e.Handled)
return;

this.AssociatedObject.Focus();

int direction = Math.Sign(e.Delta);

ScrollAmount scrollAmount =
(direction < 0) ? ScrollAmount.SmallIncrement : ScrollAmount.SmallDecrement;

if (this.Peer != null)
{
IScrollProvider scrollProvider =
this.Peer.GetPattern(PatternInterface.Scroll) as IScrollProvider;

bool shiftKey = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;

if (scrollProvider != null && scrollProvider.VerticallyScrollable && !shiftKey)
{
scrollProvider.Scroll(ScrollAmount.NoAmount, scrollAmount);
e.Handled = true;
}
else if (scrollProvider != null && scrollProvider.VerticallyScrollable && shiftKey)
{
scrollProvider.Scroll(scrollAmount, ScrollAmount.NoAmount);
e.Handled = true;
}


}
}
}


}

如何附加行为:
<data:DataGrid>
<i:Interaction.Behaviors>
<b:MouseWheelScrollBehavior />
</i:Interaction.Behaviors>
</data:DataGrid>

关于Silverlight 3 数据网格 : How to add scrollwheel support?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2273201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com