繁体   English   中英

WPF 使用 WPF ElementHost 仅在 Win 7 下具有鼠标滚轮问题的控件托管 Winforms

[英]WPF Control hosted Winforms using WPF ElementHost has Mouse Wheel Issue under Win 7 Only

我有一个与 Bing 地图一起使用的 WPF ElementHost。 .Windows 10中一切正常,但在中无法使用鼠标滚轮进行缩放。

我尝试通过为UCBingMap.MouseEnter添加事件处理程序并调用UCBingMap.Focus来确保托管元素具有焦点。 我确认它正在发射。 仍然 - 它在 Windows 7 下不起作用,但在 Windows 10 下起作用。可悲的是 - 在可预见的未来,我有很多客户坚持使用 Win7...

我的 XAML 供用户控制

<UserControl x:Class="BingMapUC"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
         mc:Ignorable="d" 
         d:DesignHeight="393" d:DesignWidth="644" IsHitTestVisible="True" Focusable="True">
<UserControl.Resources >
    <ControlTemplate x:Key="Default" TargetType="m:Pushpin">
        <Grid x:Name="ContentGrid" HorizontalAlignment="Center" VerticalAlignment="Center">
            <StackPanel>
                <Grid Margin="0" Width="24" Height="23">
                    <Rectangle HorizontalAlignment="Left"  Margin="0,3.238,0,-2.146" Width="23" Height="18" Fill="SteelBlue" Stroke="Black"  RenderTransformOrigin="0.5,0.62">
                        <Rectangle.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform/>
                                <SkewTransform AngleY="0" AngleX="-23"/>
                                <RotateTransform Angle="123"/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Rectangle.RenderTransform>
                    </Rectangle>

                    <Rectangle Fill="{TemplateBinding Background}" Stroke="Black" RadiusX="5" RadiusY="5"/>

                    <ContentPresenter HorizontalAlignment="Center"
                                                            VerticalAlignment="Center"
                                                            Content="{TemplateBinding Content}"
                                                            ContentTemplate="{TemplateBinding ContentTemplate}"
                                                            Margin="0" TextBlock.FontFamily="Segoe UI" TextBlock.FontWeight="Bold" TextBlock.Foreground="Black" >
                    </ContentPresenter>
                </Grid>
            </StackPanel>
        </Grid>
    </ControlTemplate>
</UserControl.Resources>
<Grid>
    <m:Map Name="Map" ZoomLevel="3.5" Center="38.8282,-95.5795" Cursor="Hand" CredentialsProvider="xxxxxxxxxxxxxxxxxx" Height="393" UseInertia="True" Margin="0" MaxWidth="644" MaxHeight="393" MinWidth="644" MinHeight="393" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="635" ScaleVisibility="Hidden"/>
</Grid>
</UserControl>

我希望我忽略了一些深奥的设置......

事实证明,同一表单上的另一个控件正在从 WPF ElementHost 中窃取 MouseWheel 事件(在我的情况下,它托管了一个名为 BingMapUC 的 BingMap)。 doing it under Windows 7 (SP1), but not in Windows 10. I was able to fix the problem in my VB.NET source by manually adding handlers for the ElementHost MouseEnter event.在 Windows 7 (SP1) 下执行,但不在 Windows 10 下执行。我能够通过手动为元素添加处理程序来解决我的 VB.NET 源中的问题。

AddHandler BingMapUC.MouseEnter, AddressOf BingMap_MouseEnter

在那种情况下,我手动将鼠标控件从 ListView 控件(那是窃取 MouseWheel 事件的那个)

lsvControl.Capture = False

然后我确保 BingMapUC(托管的 WPF)获得焦点

BingMapUC.Focus()

这在 Windows 10 和 Windows 7 下都有效,所以我不必检查。

我还确保在其 MouseEnter 事件中将鼠标控制权交还给列表视图

lsvControl.Capture = True

所以当鼠标在它上面时它会滚动。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM