我的 WPF 应用程序滚动时遇到问题。
这是交易。我的用户界面如下:
我的应用程序的作用是充当许多应用程序的中心枢纽并启动它们。管理员可以启动其他用户记录的转储。
因此,我有一个ListView
,显示应用程序列表,如果需要,可以滚动。
我定义了一个GroupStyle
以显示扩展器并模拟 Windows 资源管理器视图。
一切正常,我只是有一个问题:当用鼠标滚轮滚动时,透明蓝色的组件(“启动模式”)似乎抓住了焦点并停止滚动。
这尤其意味着,如果我的鼠标位于此控制之外的任何位置,则滚动是可以的。但是每当鼠标进入这个控件时,我就无法再滚动了。
我尝试修改属性Focusable
并将其设置为False
我可以到处去,但什么都没有改变。我猜这最终不是焦点问题。
有人知道如何避免滚动被元素捕获吗?
这是扩展器内容的一些(简化的,删除了一些无用的属性,以便尽可能清晰)XAML:
<StackPanel Orientation="Vertical" VerticalAlignment="Top" >
<ToggleButton>
<!-- ToggleButton Content... -->
</ToggleButton>
<!-- This is the custom component in which you can see "Launch mode" -->
<my:UcReleaseChooser >
<!-- Properties there. I tried to set Focusable to False, no impact... -->
</my:UcReleaseChooser>
</StackPanel>
和代码UcReleaseChooser
:
<StackPanel HorizontalAlignment="Stretch"
Focusable="False" ScrollViewer.CanContentScroll="False">
<ListBox ItemsSource="{Binding ListChosenReleases}" BorderBrush="LightGray" Background="AliceBlue"
HorizontalAlignment="Stretch" Focusable="False" ScrollViewer.CanContentScroll="False">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"
Focusable="False" ScrollViewer.CanContentScroll="False"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel LastChildFill="True" HorizontalAlignment="Stretch"
Focusable="False" ScrollViewer.CanContentScroll="False">
<TextBlock DockPanel.Dock="Top"
HorizontalAlignment="Left" Text="{Binding Key}"
FontStyle="Italic"/>
<ListBox DockPanel.Dock="Bottom"
HorizontalAlignment="Right" ItemsSource="{Binding Value}"
BorderBrush="{x:Null}" Background="AliceBlue"
Focusable="False" ScrollViewer.CanContentScroll="False">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Focusable="False"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<-- Blah blah about style -->
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton Content="{Binding Key}" Margin="3"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListBoxItem}}}"
Focusable="False" ScrollViewer.CanContentScroll="False"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
如您所见,UcReleaseChooser
包含一个列表RadioButton
列表。我尝试设置Focusable
& CanContentScroll
to False
它似乎在任何地方都合适,但控件不断阻止主 UI 滚动......
我想我应该改变另一个财产......有什么想法吗?
Thanks!
问题是ListBox
,或者更具体地说,ScrollViewer
内ListBox
的模板。这是获取滚动事件并在外部之前消耗它们ScrollViewer
in the ListView
甚至看到他们。
我建议更换ListBox
与ItemsControl
如果可能的话。然而,这意味着不会有SelectedItem
财产。如果你需要的话,我建议设置ScrollViewer.HorizontalScrollBarVisibility
(or VerticalScrollBarVisibility
) to Disabled
。如果做不到这一点,我只能建议重新模板ListBox
不包含ScrollViewer
at all.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)