【问题标题】:WPF Custom control deriving from UserControl not responding to MouseClick派生自 UserControl 的 WPF 自定义控件不响应 MouseClick
【发布时间】:2010-09-29 23:56:59
【问题描述】:

我有一个简单的自定义控件,它使用以下 XAML 从 UserControl 派生:

<UserControl x:Class="EMS.Controls.Dictionary.MapTip"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:slData="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
       xmlns:infrv="clr-namespace:OCC600.Infrastructure.Interface.Views;assembly=EMS.OCC600.Infrastructure.Interface"
        xmlns:igDP="http://infragistics.com/DataPresenter"       x:Name="root"                   
      > 

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Viewbox x:Name="viewBox" >
        <Border CornerRadius="10" Background="#80000000" BorderBrush="Black">                 
            <Grid Name="contentGrid" Margin="0,20,0,0" >            
                <Grid.RowDefinitions>              
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>                   
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>                  
                </Grid.ColumnDefinitions>              

                <Border Grid.Row="2" Margin="5" Grid.ColumnSpan="2" Visibility="Visible" >                                                  
                    <igDP:XamDataGrid Margin="5"                                      
                                      Name="IdentifyDetailsDataGrid"     
                                      Style="{StaticResource readonlyGrid}"  
                                      ClipToBounds="False">                        
                        <igDP:XamDataGrid.FieldLayoutSettings>
                            <igDP:FieldLayoutSettings                         
                                AutoGenerateFields="True"                                                                                                                                   
                                HighlightAlternateRecords="True"                                
                                FilterUIType="LabelIcons"
                                AllowAddNew="False" 
                                AllowDelete="False"                                                                 
                                SelectionTypeCell="Single"                                
                                SelectionTypeField="Single"                        
                                />
                        </igDP:XamDataGrid.FieldLayoutSettings>
                        <igDP:XamDataGrid.FieldSettings>
                            <igDP:FieldSettings
                                LabelClickAction="SortByOneFieldOnly"                                 
                                AllowEdit="False" 
                                AllowGroupBy="True"                                 
                                CellClickAction="SelectRecord"                            
                                ExpandableFieldRecordHeaderDisplayMode="NeverDisplayHeader"/>
                        </igDP:XamDataGrid.FieldSettings>
                    </igDP:XamDataGrid>                    
                </Border>          
        </Grid>   
        </Border>
    </Viewbox>  
</UserControl>

这里将这个 Maptip 的一个实例添加到 JSmith 提供的 DragCanvas 中:http://www.codeproject.com/KB/WPF/DraggingElementsInCanvas.aspx

此控件动态提供了一个工具栏,其中包含绑定到 ViewModel 中的命令的按钮。当我单击按钮时,什么也没有发生。但是,如果我用 System.Windows.Primitives.Popup 类替换 Maptip 的基类,则当将此 maptip 添加到拖动画布时,按钮会响应鼠标单击事件并执行命令。

关于我在这里看到的任何提示?

TIA。

【问题讨论】:

    标签: wpf


    【解决方案1】:

    与覆盖 OnPreviewMouseLeftButtonDown 的自定义 DragConvas 有关。改为覆盖 OnMouseLeftButtonDown 并且我的控件现在确实看到了鼠标点击。从链接获得线索:

    http://www.codeproject.com/KB/WPF/DraggingElementsInCanvas.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 2014-06-11
      相关资源
      最近更新 更多