2

我有一个组合框,在其中显示简单的字符串。在某些时候,这看起来如下所示:

滚动前的文本

还行吧。现在向下滚动一步:

滚动后的文本

现在“g”在底部被切断。到目前为止我已经尝试过:将 height 属性显式设置为 Auto。更改填充和边距。没有任何效果。你们中的一些人有同样的问题或有什么我可以尝试的建议吗?

编辑

这里是相关的 XAML:

<Style x:Key="GraphicEditorInplaceLabelEditStyle">
    <Setter Property="ComboBox.Focusable" Value="True"/>
    <Setter Property="ComboBox.IsEditable" Value="True"/>
    <Setter Property="ComboBox.IsReadOnly" Value="False"/>
    <Setter Property="ComboBox.IsTextSearchEnabled" Value="True"/>

    <!--Use Separators for empty entries-->
    <Setter Property="ComboBox.ItemContainerStyle">
        <Setter.Value>
            <Style TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding}" Value="">
                        <Setter Property="IsEnabled" Value="False"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                                    <Separator HorizontalAlignment="Stretch"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Setter.Value>
    </Setter>

    <Setter Property="ComboBox.Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Border Validation.ValidationAdornerSiteFor="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=ComboBox}}" Background="{StaticResource ComboBoxActiveBackgroundBrush}" BorderBrush="{StaticResource ComboBoxBorderBrush}" BorderThickness="1" CornerRadius="2">
                        <Grid>
                            <ContentPresenter Margin="3,3,3,3" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" HorizontalAlignment="Left" IsHitTestVisible="False" Name="ContentSite" VerticalAlignment="Center" />
                            <TextBlock Style="{x:Null}" x:Name="PART_TextBackground" Margin="3,3,3,3" Background="Transparent" Focusable="False" FontStyle="Italic" Foreground="LightGray" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                            <TextBox Style="{x:Null}" x:Name="PART_EditableTextBox" Margin="3,3,3,3" Background="Transparent" Focusable="True" HorizontalAlignment="Left" IsReadOnly="{TemplateBinding IsReadOnly}" VerticalAlignment="Center" Visibility="Hidden">
                                <TextBox.Template>
                                    <ControlTemplate TargetType="TextBox">
                                        <Border x:Name="PART_ContentHost" Background="{TemplateBinding Background}" Focusable="False" />
                                    </ControlTemplate>
                                </TextBox.Template>
                            </TextBox>
                            <Popup AllowsTransparency="True" Focusable="False" IsOpen="{TemplateBinding IsDropDownOpen}" Name="Popup" Placement="Bottom" PopupAnimation="Slide">
                                <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" Name="DropDown" SnapsToDevicePixels="True">
                                    <Border x:Name="DropDownBorder" Background="{StaticResource ComboBoxActiveBackgroundBrush}" BorderBrush="{StaticResource ComboBoxBorderBrush}" BorderThickness="1" />
                                    <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" CanContentScroll="False">
                                        <StackPanel KeyboardNavigation.DirectionalNavigation="Contained" IsItemsHost="True" />
                                    </ScrollViewer>
                                </Grid>
                            </Popup>
                        </Grid>
                    </Border>

                    <ToggleButton Grid.Column="1" ClickMode="Press" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" Name="ToggleButton" VerticalAlignment="Bottom">
                        <ToggleButton.Template>
                            <ControlTemplate TargetType="ToggleButton">
                                <Grid>
                                    <Border x:Name="Border"
                            CornerRadius="2"
                            Background="{StaticResource ComboBoxActiveBackgroundBrush}"
                            BorderBrush="{StaticResource ComboBoxBorderBrush}"
                            BorderThickness="1"
                            Margin="0,0,0,0" />

                                    <Rectangle x:Name="arrow"
                               Height="6"
                               Width="8"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"
                               Margin="2"
                               Fill="{StaticResource ComboBoxArrowDownBrush}" />
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="ToggleButton.IsMouseOver"
                             Value="true">
                                        <Setter TargetName="Border"
                                Property="Background"
                                Value="{StaticResource ComboBoxMouseOverBackgroundBrush}" />
                                        <Setter TargetName="arrow"
                                Property="Fill"
                                Value="{StaticResource ComboBoxArrowDownMouseOverBrush}"></Setter>
                                    </Trigger>
                                    <Trigger Property="ToggleButton.IsChecked"
                             Value="true">
                                        <Setter TargetName="Border"
                                Property="Background"
                                Value="{StaticResource ComboBoxPressedBackgroundBrush}" />
                                        <Setter Property="Fill"
                                TargetName="arrow"
                                Value="{StaticResource ComboBoxArrowUpBrush}" />
                                    </Trigger>
                                    <Trigger Property="IsEnabled"
                             Value="false">
                                        <Setter TargetName="Border"
                                Property="Background"
                                Value="{StaticResource ComboBoxInactiveBackgroundBrush}" />
                                        <Setter Property="Foreground"
                                Value="{StaticResource FontInactiveBrush}" />
                                        <Setter Property="Fill"
                                TargetName="arrow"
                                Value="{StaticResource ComboBoxArrowDownInactiveBrush}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </ToggleButton.Template>
                        <ToggleButton.RenderTransform>
                            <TranslateTransform X="-3" Y="0"></TranslateTransform>
                        </ToggleButton.RenderTransform>
                    </ToggleButton>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasItems" Value="false">
                        <Setter Property="Visibility" TargetName="ToggleButton" Value="Collapsed" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{StaticResource FontInactiveBrush}" />
                    </Trigger>
                    <Trigger Property="IsGrouping" Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
                    </Trigger>
                    <Trigger Property="Popup.AllowsTransparency" SourceName="Popup" Value="true">
                        <Setter Property="CornerRadius" TargetName="DropDownBorder" Value="4" />
                        <Setter Property="Margin" TargetName="DropDownBorder" Value="0,2,0,0" />
                    </Trigger>
                    <Trigger Property="IsEditable" Value="true">
                        <Setter Property="IsTabStop" Value="false" />
                        <Setter Property="Visibility" TargetName="PART_EditableTextBox" Value="Visible" />
                        <Setter Property="Visibility" TargetName="ContentSite" Value="Hidden" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我试图更改 ComboBoxItem 的填充/边距以及项目主机堆栈面板。

4

0 回答 0