【问题标题】:WPF combobox items list/context menu rendered behind parentWPF 组合框项目列表/上下文菜单呈现在父级后面
【发布时间】:2011-03-05 19:28:59
【问题描述】:

如果设置了组合框的ItemSource属性,为什么单击组合框的下拉按钮不能显示可用项目列表?这可能是相关的,但在同一个控件中,任何上下文菜单都显示在用户控件后面:

此控件的 XAML 如下:

 <Border Name="Border" Padding="5">
        <ScrollViewer VerticalScrollBarVisibility="Auto">
            <ScrollViewer.Resources>
                <Style TargetType="{x:Type CheckBox}">
                    <Setter Property="Padding" Value="8,0,0,0"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>            
            </ScrollViewer.Resources>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>                          
                    <Grid Margin="5,4,0,4" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20" />
                            <ColumnDefinition SharedSizeGroup="labelColumn1" />
                            <ColumnDefinition  SharedSizeGroup="labelColumn2" />
                            <ColumnDefinition SharedSizeGroup="dataEntryColumn" />
                            <ColumnDefinition  Width="30"/>
                            <ColumnDefinition  SharedSizeGroup="labelColumn2"/>
                            <ColumnDefinition SharedSizeGroup="dataEntryColumn" />
                            <ColumnDefinition MaxWidth="0" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition MinHeight="23" />
                            <RowDefinition MinHeight="23" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto"/>

                        </Grid.RowDefinitions>

                        <TextBlock Text="Geometry Type" VerticalAlignment="Center" Grid.Column="1" Grid.Row="0"/>                       
                        <ComboBox Grid.Column="3" Margin="6,1,0,1"   Grid.Row="0" Width="150"  
                                  Name="cmboGeometryTypes"   
                                  SelectedItem="{Binding GeometryType, Mode=TwoWay}"
                                  HorizontalAlignment="Left"   
                                  DisplayMemberPath="Name"                                   
                                  Grid.ColumnSpan="1"                                      
                                 />

                        <TextBlock Text="Symbol Type" 
                                   Grid.Column="1" Grid.Row="1" VerticalAlignment="Center"/>
                        <ComboBox
                            Name="cmboSymbolEditors"
                            SelectedItem="{Binding SymbolEditorViewModel, Mode=TwoWay}"
                            HorizontalAlignment="Left"   
                            DisplayMemberPath="Alias" 
                            Width="150"
                            Grid.Column="3" 
                            Margin="6,1,0,1" 
                            Grid.Row="1"                            
                            Grid.ColumnSpan="1"  />               
                </Grid>

                <Label Padding="10,0,0,0" Margin="10,0,0,3" Style="{StaticResource fadingLabelSeperatorStlye}" Grid.Row="1">
                    Editor
                </Label>
                <local:SymbologyEditorControl x:Name="editor" Grid.Row="2"/>                               
            </Grid>
        </ScrollViewer>
    </Border>

我观察到的效果如下图

我该如何解决这个问题?

【问题讨论】:

  • 首先,您是否尝试过添加边距,以便查看它是否真的在 UI 的其余部分之后,或者根本没有绘制
  • 不,我没有这样做。但是,如果我使用 ListBox,我确实会看到组合框未显示的可用项目列表。鉴于上下文菜单的相关问题,我怀疑组合框列表是在父级后面绘制的。

标签: wpf combobox contextmenu


【解决方案1】:

有一个常见的 WPF 错误导致任何 Popup 类型的 UI 显示在后面而不是最顶部,所以这可能就是您所看到的。我有一段时间没有看到这个问题,但我不确定它是否已修复。它与不良的视频驱动程序有关,因此您可能只在某些机器上看到它,而不是一直看到它。

MS 支持提供了一个修补程序,但将应用程序切换为使用软件渲染可能更容易。

【讨论】:

  • 您是正确的,它不会发生在安装了非常机器的应用程序上。将寻找修补程序,谢谢。
猜你喜欢
  • 1970-01-01
  • 2011-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多