如何为 RibbonComboBox 启用 ScrollViewer?
How to enable ScrollViewer for RibbonComboBox?
使用下面的代码,字体下拉列表从屏幕上消失。设置 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>
回答我自己的问题:这似乎或多或少符合我的要求。
<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>
使用下面的代码,字体下拉列表从屏幕上消失。设置 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>
回答我自己的问题:这似乎或多或少符合我的要求。
<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>