我們有一個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