我需要一个全局上下文菜单的样式/模板,它有一个标题和各种菜单项;由于我的上下文菜单中菜单项的数量可能很大,因此它需要支持滚动。
我目前使用的样式的问题是它不支持滚动;即使菜单项的数量超过屏幕大小,也没有显示滚动条。
这是我目前正在使用的样式 -
将滚动查看器放在标题上方可以实现,但是标题也会被滚动。如何最好地实现这一点?
我目前使用的样式的问题是它不支持滚动;即使菜单项的数量超过屏幕大小,也没有显示滚动条。
这是我目前正在使用的样式 -
<Style
TargetType="{x:Type ContextMenu}"
x:Key="ContextMenuStyle">
<Setter
Property="ContextMenu.Template">
<Setter.Value>
<ControlTemplate>
<Border
BorderBrush="#868686"
BorderThickness="1"
Background="#FAFAFA">
<StackPanel
Orientation="Vertical">
<Label
Foreground="White"
Background="Blue">
<Binding
RelativeSource=
"{RelativeSource AncestorType=
{x:Type ContextMenu}}"
Path="PlacementTarget.Tag" />
</Label>
<Grid>
<Rectangle
Margin="1,1,1,1"
Width="25"
HorizontalAlignment="Left"
Fill="#E9EEEE" />
<Rectangle
Margin="26,1,0,1"
Width="1"
HorizontalAlignment="Left"
Fill="#C5C5C5" />
<Rectangle
Margin="27,1,0,1"
Width="1"
HorizontalAlignment="Left"
Fill="#FAFAFA" />
<ScrollViewer
Margin="1,0,1,0"
Style="{DynamicResource
{ComponentResourceKey
ResourceId=MenuScrollViewer,
TypeInTargetAssembly=
{x:Type FrameworkElement}}}"
CanContentScroll="True"
Grid.ColumnSpan="2">
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation=
"Cycle" />
</ScrollViewer>
</Grid>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
将滚动查看器放在标题上方可以实现,但是标题也会被滚动。如何最好地实现这一点?