我在我的WPF应用程序中遇到了滚动问题。
我的UI如下所示:
我的应用程序的作用是作为许多应用程序的中央枢纽并启动它们。管理员可以启动由另一个用户记录的转储。
因此,我有一个ListView,显示应用程序列表,如果需要,可以滚动。我定义了一个GroupStyle以显示扩展器并模拟Windows资源管理器视图。
一切都很好,只是我有一个问题:当使用鼠标滚轮滚动时,清晰蓝色组件(“启动模式”)似乎会捕捉焦点并停止滚动。
这意味着特别是如果我的鼠标在此控件之外的任何地方,滚动就没问题。但是每当鼠标进入此控件时,我就无法再滚动了。
我尝试修改Focusable属性,并将其设置为False,但没有任何改变。我猜最终不是一个焦点问题。
有人有想法如何避免被元素捕获滚动吗?
以下是扩展器内容的XAML(已简化,删除了一些无用的属性,以使其尽可能清晰)。
如您所见,
我猜我应该改变另一个属性... 有什么建议吗?
谢谢!
我的UI如下所示:
我的应用程序的作用是作为许多应用程序的中央枢纽并启动它们。管理员可以启动由另一个用户记录的转储。
因此,我有一个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
为 False
,但该控件仍然会阻止主 UI 滚动...我猜我应该改变另一个属性... 有什么建议吗?
谢谢!
ScrollBarVisibility
设置为 Disabled 没有改变任何东西,而且重新模板化ListBox
对我来说似乎太困难了。因此,我使用了 Simon Fox 在这个 stackoverflow 问题中描述的技巧:https://dev59.com/mHI95IYBdhLWcg3wtwRe :) 不管怎样,还是感谢您确认我的问题! - Damascus