如何为RibbonComboBox启用ScrollViewer?

问题描述 投票:0回答:1

使用以下代码,字体的下拉列表在屏幕上运行。设置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>
wpf xaml ribbon
1个回答
0
投票

回答我自己的问题:这似乎做了我想要的,或多或少。

<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>
© www.soinside.com 2019 - 2024. All rights reserved.