簡體   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