wpf - 如何为 RibbonComboBox 启用 ScrollViewer?
问题描述
使用以下代码,字体的下拉列表会在屏幕外运行。设置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>
推荐阅读
- cocoahttpserver - CocoaHTTPServer 是否支持流式响应?
- mysql - 如何让查询包含来自另一个表的名称及其名称的 id
- java - 当一个线程死了它的对象会发生什么?
- python - KeyError: 'input_1_ib-0' 当我保存我的自动编码器模型时
- openedge - 如何以 30 分钟为间隔对 24 小时数据进行分组以获取计数?
- javascript - React:重新加载页面后不再获取数据
- jquery - 平滑滚动偏移在 iOS Safari 上不起作用
- python - 递归查找最后一位数字总和
- ringcentral - RingCentral 选择扩展用户并将他们从应用程序中注销
- php - 带有 API 的 ERC20 交易列表