Как включить ScrollViewer для RibbonComboBox? - PullRequest
0 голосов
/ 06 апреля 2019

Используя следующий код, выпадающий список шрифтов исчезает с экрана. Настройка ScrollViewer не показывает полосы прокрутки, как я ожидал. Вторая проблема заключается в том, что я могу перемещать мышь в раскрывающемся списке, но не прокручивать мышь с помощью колесика мыши.

<RibbonComboBox 
    xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    ItemTemplate="{DynamicResource FontTemplate}"
    ScrollViewer.VerticalScrollBarVisibility="Visible"
    ScrollViewer.HorizontalScrollBarVisibility="Visible">

    <RibbonComboBox.Resources>
        <CollectionViewSource x:Key="myFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="Source" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
        <Style x:Key="FontStyle">
            <Setter Property="Control.FontFamily" Value="{Binding Source}" />
            <Setter Property="Control.FontSize" Value="16" />
        </Style>
        <DataTemplate x:Key="FontTemplate">
            <StackPanel VirtualizingStackPanel.IsVirtualizing="False">
                <TextBlock Style="{StaticResource FontStyle}"
                   Text="{Binding Source}"
                   ToolTip="{Binding Source}" />
            </StackPanel>
        </DataTemplate>
    </RibbonComboBox.Resources>

    <RibbonComboBox.ItemsSource>
        <Binding Source="{StaticResource myFonts}"/>
    </RibbonComboBox.ItemsSource>

</RibbonComboBox>

1 Ответ

0 голосов
/ 06 апреля 2019

Отвечая на мой собственный вопрос: кажется, это делает то, что я хочу, более или менее.

<RibbonComboBox xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase">
    <RibbonComboBox.Resources>
        <CollectionViewSource x:Key="myFonts" Source="{Binding Source={x:Static Fonts.SystemFontFamilies}}">
            <CollectionViewSource.SortDescriptions>
                <ComponentModel:SortDescription PropertyName="Source" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
        <Style x:Key="FontStyle">
            <Setter Property="Control.FontFamily" Value="{Binding Source}" />
            <Setter Property="Control.FontSize" Value="16" />
        </Style>
        <DataTemplate x:Key="FontTemplate">
            <RibbonGalleryItem>
                <TextBlock Style="{StaticResource FontStyle}"
                   Text="{Binding Source}"
                   ToolTip="{Binding Source}"/>
            </RibbonGalleryItem>
        </DataTemplate>
        <DataTemplate x:Key="myFontTemplate">
            <RibbonGalleryItem>
                <TextBlock Style="{StaticResource FontStyle}"
                   Text="{Binding Source}"
                   ToolTip="{Binding Source}" />
            </RibbonGalleryItem>
        </DataTemplate>
    </RibbonComboBox.Resources>
    <RibbonGallery Name="RibbonGallery" MaxColumnCount="1">
        <RibbonGalleryCategory ItemsSource="{Binding Source={StaticResource myFonts}}"
                   ItemTemplate="{DynamicResource myFontTemplate}"
                   ScrollViewer.VerticalScrollBarVisibility="Auto"
                   ScrollViewer.CanContentScroll="True"/>
    </RibbonGallery>
</RibbonComboBox>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...