コマンドをCtrl+MWheelUp/Down
にバインドする方法はありますか?あなたはブラウザで知っている、あなたはフォントサイズを増減するために同じことをすることができますか?私はWPFでその効果を再現したい。可能?私はInputBinding>MouseBindingsを見ていて、MouseActionはマウススクロールをサポートしていないようです。WPF InputBinding Ctrl + MWheelUp/Down可能ですか?
*私はもう
コマンドをCtrl+MWheelUp/Down
にバインドする方法はありますか?あなたはブラウザで知っている、あなたはフォントサイズを増減するために同じことをすることができますか?私はWPFでその効果を再現したい。可能?私はInputBinding>MouseBindingsを見ていて、MouseActionはマウススクロールをサポートしていないようです。WPF InputBinding Ctrl + MWheelUp/Down可能ですか?
*私はもう
は[OK]を、私は行動の方法は、物事はよりクリーンで再利用可能になりますが、私は実際に取得していないと思う私のShellView : Window
this.KeyDown += (s, e) =>
{
_leftCtrlPressed = (e.Key == Key.LeftCtrl) ? true : false;
};
this.MouseWheel += (s, e) =>
{
if (_leftCtrlPressed) {
if (e.Delta > 0)
_vm.Options.FontSize += 1;
else if (e.Delta < 0)
_vm.Options.FontSize -= 1;
}
};
にこのような何かをしましたそれ。誰かがここで簡単な方法でそれを説明すれば、それは素晴らしいことでしょうか?私は単にInteraction.Triggersを使用してコマンドをバインド
<MouseBinding Gesture="{local:MouseWheel Direction=Down, Keys=Control}" Command="..." />
ウィンドウはマウスホイールイベントがあります同様の質問を掲載しているように見えるが、それを見つけることができません。いくつかのコマンドバインディングマジックを実行し、DataContextプロパティにバインドすることができます。ヒントについては、このSOの記事をチェックしてください:Key press inside of textbox MVVM。また、この記事を見てみましょう:http://code.msdn.microsoft.com/eventbehaviourfactor
これは非常に単純なカスタムMouseGestureを使用して行うことができます。
XAMLの式の対話性名前空間を参照する必要があります。
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseWheel">
<cmd:InvokeCommandAction Command="{Binding MouseWheelCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
次に、関連付けられたコマンド。
private void MouseWheelCommandExecute(MouseWheelEventArgs e)
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
if (e.Delta > 0)
{
if (Properties.Settings.Default.ZoomLevel < 4)
Properties.Settings.Default.ZoomLevel += .1;
}
else if (e.Delta < 0)
{
if (Properties.Settings.Default.ZoomLevel > 1)
Properties.Settings.Default.ZoomLevel -= .1;
}
}
}
デルタが上昇している場合は、マウスがスクロールしていて、下にスクロールしています。スクロール可能なコンテンツでスクロールが発生するアプリケーションでこれを使用しますが、いずれかのCtrlキーが押されていない場合は、アプリケーションが実際にズームします。
:XAMLで
public enum MouseWheelDirection { Up, Down}
class MouseWheelGesture:MouseGesture
{
public MouseWheelDirection Direction { get; set; }
public MouseWheelGesture(ModifierKeys keys, MouseWheelDirection direction)
: base(MouseAction.WheelClick, keys)
{
Direction = direction;
}
public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
{
var args = inputEventArgs as MouseWheelEventArgs;
if (args == null)
return false;
if (!base.Matches(targetElement, inputEventArgs))
return false;
if (Direction == MouseWheelDirection.Up && args.Delta > 0
|| Direction == MouseWheelDirection.Down && args.Delta < 0)
{
inputEventArgs.Handled = true;
return true;
}
return false;
}
}
public class MouseWheel : MarkupExtension
{
public MouseWheelDirection Direction { get; set; }
public ModifierKeys Keys { get; set; }
public MouseWheel()
{
Keys = ModifierKeys.None;
Direction = MouseWheelDirection.Down;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return new MouseWheelGesture(Keys, Direction);
}
}
: