1

コンボボックスのドロップダウン リストを、コンボボックスの contentPresenter のオフセット (選択した項目を表示する部分) から直接開く必要があります。しかし実際には、ドロップダウン リストのオフセットが contentPresenter の上にあり、ページの上限まであるということが起こります。

同様に、ドロップダウンリストの幅を最大のアイテムに合わせて永続的に変更し、現在のように動的に変更しないようにします(現在、表示されているアイテムに応じてサイズが変更されました)。

ここに画像の説明を入力

コンボ ボックスの MaxDropDownHeight プロパティを 0 または 300 に設定しようとしましたが、何も変わりません。

これが templateControl です (画像はこのスニペットとは関係ありません):

<Style TargetType="ComboBox" >
        <Setter Property="Padding" Value="8,0" />
        <Setter Property="FlowDirection" Value="LeftToRight" />
        <Setter Property="Foreground" Value="{StaticResource ComboBoxForegroundThemeBrush}" />
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderBrush" Value="Gray" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="TabNavigation" Value="Once" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
        <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True" />
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
        <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <CarouselPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="32" />
                        </Grid.ColumnDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="PointerOver">
                                    <!--
                                        <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPointerOverBackgroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPointerOverBorderThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="Highlight">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxSelectedPointerOverBackgroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    -->
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <!--
                                        <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPressedBackgroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPressedBorderThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPressedForegroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PressedBackground"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DropDownGlyph">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxArrowPressedForegroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    -->
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <!--
                                        <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxDisabledBackgroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Background">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxDisabledBorderThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxDisabledForegroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DropDownGlyph">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxArrowDisabledForegroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    -->
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <!--
                                        <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Highlight"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxFocusedForegroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    -->
                                </VisualState>
                                <VisualState x:Name="FocusedPressed">
                                    <!--
                                        <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPressedForegroundThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="Highlight">
                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource ComboBoxPressedHighlightThemeBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    -->
                                </VisualState>
                                <VisualState x:Name="Unfocused" />
                                <VisualState x:Name="PointerFocused" />
                                <VisualState x:Name="FocusedDropDown">
                                    <!--
                                        <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="PopupBorder">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                        <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                        </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    -->
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="DropDownStates">
                                <VisualState x:Name="Opened">
                                    <!--
                                        <Storyboard>
                                        <SplitOpenThemeAnimation ClosedTargetName="ContentPresenter" ContentTranslationOffset="0" ContentTargetName="ScrollViewer" ClosedLength="{Binding TemplateSettings.DropDownClosedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" OffsetFromCenter="{Binding TemplateSettings.DropDownOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" OpenedTargetName="PopupBorder" OpenedLength="{Binding TemplateSettings.DropDownOpenedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                                        </Storyboard>
                                    -->
                                </VisualState>
                                <VisualState x:Name="Closed">
                                    <!--
                                        <Storyboard>
                                        <SplitCloseThemeAnimation ClosedTargetName="ContentPresenter" ContentTranslationOffset="40" ContentTranslationDirection="{Binding TemplateSettings.SelectedItemDirection, RelativeSource={RelativeSource Mode=TemplatedParent}}" ContentTargetName="ScrollViewer" ClosedLength="{Binding TemplateSettings.DropDownClosedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}" OffsetFromCenter="{Binding TemplateSettings.DropDownOffset, RelativeSource={RelativeSource Mode=TemplatedParent}}" OpenedTargetName="PopupBorder" OpenedLength="{Binding TemplateSettings.DropDownOpenedHeight, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                                        </Storyboard>
                                    -->
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="Background"
                                Grid.ColumnSpan="2"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="2" />
                        <Rectangle x:Name="PressedBackground"
                                   Margin="{TemplateBinding BorderThickness}"
                                   Fill="{StaticResource ComboBoxPressedHighlightThemeBrush}"
                                   Opacity="0" />
                        <Border x:Name="HighlightBackground"
                                Grid.ColumnSpan="2"
                                Background="{StaticResource ComboBoxFocusedBackgroundThemeBrush}"
                                BorderBrush="{StaticResource ComboBoxFocusedBorderThemeBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Opacity="0" />
                        <Rectangle x:Name="Highlight"
                                   Margin="{TemplateBinding BorderThickness}"
                                   Fill="{StaticResource ComboBoxSelectedBackgroundThemeBrush}"
                                   Opacity="0" />
                        <ContentPresenter x:Name="ContentPresenter"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        <TextBlock x:Name="DropDownGlyph"
                                   Grid.Column="1"
                                   Margin="0,0,6,4"
                                   HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   FontFamily="{StaticResource SymbolThemeFontFamily}"
                                   FontSize="{StaticResource ComboBoxArrowThemeFontSize}"
                                   FontWeight="Bold"
                                   Foreground="Red"
                                   IsHitTestVisible="False"
                                   Text="" />
                        <Popup x:Name="Popup">
                            <Border x:Name="PopupBorder"
                                    HorizontalAlignment="Stretch"
                                    Background="{StaticResource ComboBoxPopupBackgroundThemeBrush}"
                                    BorderBrush="{StaticResource ComboBoxPopupBorderThemeBrush}"
                                    BorderThickness="{StaticResource ComboBoxPopupBorderThemeThickness}">
                                <ScrollViewer x:Name="ScrollViewer"
                                              BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
                                              Foreground="{StaticResource ComboBoxPopupForegroundThemeBrush}"
                                              HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                              HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                              IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                              IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                              IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                              VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                              VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                              VerticalSnapPointsAlignment="Near"
                                              VerticalSnapPointsType="OptionalSingle"
                                              ZoomMode="Disabled">
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </Border>
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

ありがとう!

4

2 に答える 2

1

ComboBox のフェースプレートのサイズを最大のアイテムに合わせるには、ComboBox.Width (または ComboBox.MinWidth に最小値を設定し、より大きなアイテムの場合は拡大できるようにする) に明示的な値を設定します。これは、最長のアイテムの長さが事前にわかっている場合に機能します。

ComboBox の CarouselPanel は VirtualizingPanel を継承しているため、項目を仮想化できるため、最も長い項目の長さを判断するのは困難です。ここでは、幅を明示的に設定するのがおそらく最善の方法です。

ComboBox ポップアップの配置に関しては、配置ロジックは実装の詳細であり、私の知る限り API を通じて公開されていません。ComboBox の設計は、タッチ、マウス、およびキーボードのユーザーに配慮した ComboBox の Win8 設計ガイドラインに従います。ユーザーは ComboBox がどのように開くかについて期待しているため、可能であればここのガイドラインに従うことをお勧めします。上記のカスタム動作を実現する必要がある場合は、ComboBox コントロールをハックして実行するか、カスタム ソリューションを作成することができます。

于 2013-05-14T06:30:21.210 に答える
0

スタイルで、コンボボックスの項目パネルを carouselpanel から stackpanel に変更してみてください。そうすれば、仮想化の問題とコンボボックスが両側で開く問題が解決される可能性があります。

(今は自分で確認できません)

于 2013-05-16T18:49:46.010 に答える