我们有一个UserControl
显示ListBox
中表示为RadioButton
的枚举的所有可能值以选择其中之一。当此控件与ScrollViewer
以及其他控件(如文本框或任何其他控件)一起使用时,如果尝试使用鼠标滚轮进行滚动,则当鼠标光标位于EnumBox上方时,它不会滚动窗体的ScrollViewer
。避免UserControl捕捉鼠标滚轮滚动
这是怎么看起来像在UI:
出于演示的RadioButton
■找黄色的背景下,WrapPanel
的背景是绿色的。当鼠标光标在彩色区域内时(例如在WrapPanel
内),用鼠标滚轮滚动不起作用。
的模板EnumBox看起来是这样的:
<UserControl.Template>
<ControlTemplate TargetType="{x:Type clientsWpf:EnumBox}">
<StackPanel>
<GroupBox Header="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type clientsWpf:EnumBox}}}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource AncestorType={x:Type clientsWpf:EnumBox}}}">
<Border x:Name="InvalidBorder" BorderBrush="Red" BorderThickness="0" >
<ListBox x:Name="PART_ListBox" HorizontalAlignment="Left" KeyboardNavigation.DirectionalNavigation="Cycle" Background="Transparent" BorderThickness="0" SelectedValuePath="." SelectedValue="{Binding Path=SelectedValue, RelativeSource={RelativeSource AncestorType={x:Type clientsWpf:EnumBox}}}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Background="Green"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Resources>
<Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Transparent" Background="Yellow">
<RadioButton Margin="3" Focusable="False" Content="{TemplateBinding ContentControl.Content,Converter={StaticResource enumValueDescriptionConverter}}"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Resources>
</ListBox>
</Border>
</GroupBox>
</StackPanel>
</ControlTemplate>
</UserControl.Template>
我试图设置ScrollViewer.VerticalScrollBarVisibility="Disabled"
和ScrollViewer.CanContentScroll="False"
在ListBox
,WrapPanel
,RadioButton
及其Border
有没有影响。
我试图抓住所有四个控件上的ScrollBar.Scroll="WrapPanel_Scroll"
事件,但没有一个被击中。
我试图设置SelectiveScrollingGrid.SelectiveScrollingOrientation="None"
在RadioButton
没有任何效果。
有没有人有什么阻止在用户界面中滚动的线索?
要说清楚:它不是关于在EnumBox中滚动,而是滚动整个表单。
尝试一件事情,点击控制,然后使用鼠标滚轮进行滚动,如果它能正常工作,则需要在窗体上激活时将焦点设置为控件 – Habib 2012-04-20 09:32:12
@ Habib.OUS:这没有帮助。我希望很清楚,我想要在整个表单/页面/网格/窗口或EnumBox所属的UI中进行上下滚动。我不想在EnumBox中滚动。 – gumo 2012-04-20 12:54:31