无法移动关注文本框的图像?

时间:2015-01-29 11:14:18

标签: c# wpf

我需要使用control key + arrows移动图像, if (Keyboard.Modifiers == ModifierKeys.Control) { if (e.SystemKey == Key.Up || e.Key == Key.Up || e.SystemKey == Key.Down || e.Key == Key.Down || e.SystemKey == Key.Right || e.Key == Key.Right || e.SystemKey == Key.Left || e.Key == Key.Left) { if (ImagePreviewActions.KeyDownAction != null) { ImagePreviewActions.KeyDownAction.Invoke(e); e.Handled = true; } } <local:ImagePreview x:Name="imgPreview_Credit" ImageSource="{Binding SelectedCreditImage.Image, Mode=OneWay}" EnableKeyEvents="False" EnableCrop="False" EnableZoom="True" FitImageToControl="True" FunGetCroppedImageInBytes="{Binding CreditImagePreviewActions.FunGetCroppedImageInBytes, Mode=OneWayToSource}" ImageCropCompletedAction="{Binding CreditImagePreviewActions.ImageCropCompletedAction, Mode=OneWay}" KeyAction="{Binding CreditImagePreviewActions.KeyDownAction, Mode=OneWayToSource}" ScrollViewStyle="{DynamicResource ScrollViewerStyle}" Width="935.342" Height="273" ZoomAction="{Binding CreditImagePreviewActions.ZoomAction, Mode=OneWayToSource}" RotateAction="{Binding CreditImagePreviewActions.RotateAction, Mode=OneWayToSource}" ResetAndFitImageAction="{Binding CreditImagePreviewActions.ResetAndFitImageAction, Mode=OneWayToSource}" /> 位于网格中,重点放在文本框上。

KeyDownEvent中的代码:

     <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:local="clr-namespace:Smi.Smart.Common.UI.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style TargetType="{x:Type local:ImagePreview}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:ImagePreview}">

                <StackPanel x:Name="PART_spanel"  
                        Width="{Binding Path=Width,RelativeSource={RelativeSource TemplatedParent}}" 
                        Height="{Binding Path=Height,RelativeSource={RelativeSource TemplatedParent}}">
                    <Canvas>
                        <ScrollViewer Name="PART_scrl"   VerticalScrollBarVisibility="Auto"

                      Style="{Binding ScrollViewStyle, RelativeSource={RelativeSource TemplatedParent}}"
                      HorizontalScrollBarVisibility="Auto" VerticalAlignment="Top" 
                        Width="{Binding Path=Width,RelativeSource={RelativeSource TemplatedParent}}" 
                        Height="{Binding Path=Height,RelativeSource={RelativeSource TemplatedParent}}"
                              CanContentScroll="True">
                            <Canvas x:Name="PART_canvasForImage"   HorizontalAlignment="Center"
                                 VerticalAlignment="{Binding Path=CanvasVerticalAlignment,RelativeSource={RelativeSource TemplatedParent}}" 

                                >
                                <Image x:Name="PART_imageDisplay" 
                               Source="{Binding Path=ImageSource,RelativeSource={RelativeSource TemplatedParent}}"
                                   VerticalAlignment="Top"
                                   Canvas.Left="0" Canvas.Top="0" RenderOptions.BitmapScalingMode="HighQuality">
                                    <Image.RenderTransform>
                                        <TransformGroup>
                                            <TranslateTransform />
                                            <ScaleTransform x:Name="PART_imageDisplayScaleTransform"/>
                                            <RotateTransform />
                                        </TransformGroup>
                                    </Image.RenderTransform>
                                </Image>
                            </Canvas>
                        </ScrollViewer>
                        <Line x:Name="PART_ruler" X1="0" Y1="100" X2="300" Y2="100" Stroke="Red" StrokeThickness="2"/>
                    </Canvas>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

ImagePreview是下面的自定义控件是它的代码 XAML -

{{1}}

但它在系统密钥中显示为无

1 个答案:

答案 0 :(得分:0)

从你的代码示例中很难理解你究竟想要实现什么,或者更准确地说你是如何实现它的

值为“无”的原因是因为控制键和箭头键不是系统键。

请参阅https://stackoverflow.com/a/3100000/1195341

相关问题