WPF Scroll&焦点转变的问题 [英] WPF Scroll & focus changing problem

查看:152
本文介绍了WPF Scroll&焦点转变的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在滚动WPF应用程序时遇到问题。



这是交易。我的用户界面如下:



我的应用程序的作用是充当许多应用程序的中心中心,并启动它们。管理员可以启动其他用户记录的转储。
因此,我有一个 ListView ,显示应用程序列表,如果需要可以滚动。
我定义了一个 GroupStyle 来显示扩展器和模拟Windows资源管理器视图。
一切工作正常,我只是有一个问题:滚动鼠标滚轮时,在清晰的蓝色(启动模式)组件似乎是捕捉焦点,并停止滚动。
这意味着特别是如果我的鼠标在任何地方超出了这个控制范围,滚动就没问题。但是,只要鼠标进入这个控制,我不能再滚动。
我试图修改属性 Focusable ,并将其设置为 False ,但是没有任何改变。我猜想这终究不是焦点问题。
有人知道如何避免滚动被元素捕获吗?

这里有一些(简化,删除了一些无用的属性,以便使它尽可能清楚)XAML为扩展器的内容:

 < StackPanel Orientation =VerticalVerticalAlignment =Top> ; 

< ToggleButton>
<! - ToggleButton Content ... - >
< / ToggleButton>

<! - 这是自定义组件,您可以在其中看到启动模式 - >
< my:UcReleaseChooser>
<! - 在那里的属性。我试图将Focusable设置为False,没有影响... - >
< / my:UcReleaseChooser>

< / StackPanel>

代码 UcReleaseChooser



 < StackPanel Horizo​​ntalAlignment =Stretch
Focusable =FalseScrollViewer.CanContentScroll =False>

< ListBox ItemsSource ={Binding ListChosenReleases}BorderBrush =LightGrayBackground =AliceBlue
Horizo​​ntalAlignment =StretchFocusable =FalseScrollViewer.CanContentScroll =False >

< ListBox.ItemsPanel>
< ItemsPanelTemplate>
< StackPanel Orientation =Vertical
Focusable =FalseScrollViewer.CanContentScroll =False/>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>

< ListBox.ItemTemplate>
< DataTemplate>
< DockPanel LastChildFill =TrueHorizo​​ntalAlignment =Stretch
Focusable =FalseScrollViewer.CanContentScroll =False>
< TextBlock DockPanel.Dock =Top
Horizo​​ntalAlignment =LeftText ={Binding Key}
FontStyle =Italic/>
< ListBox DockPanel.Dock =Bottom
Horizo​​ntalAlignment =RightItemsSource ={Binding Value}
BorderBrush ={x:Null}Background =AliceBlue
Focusable =FalseScrollViewer.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 =FalseScrollViewer.CanContentScroll =False/>
< / DataTemplate>
< /ListBox.ItemTemplate>
< / ListBox>
< / DockPanel>
< / DataTemplate>
< /ListBox.ItemTemplate>

< / ListBox>

< / StackPanel>

如您所见, UcReleaseChooser 包含列表 RadioButton 列表。我尝试设置 Focusable & CanContentScroll False 在任何地方似乎都是合适的,但是控件一直阻止主UI滚动...



我想我应该改变另一个属性...任何想法?
$ b $ p

谢谢!
问题是 ListBox ,或者更具体地说, ScrollViewer code> ListBox 的模板中。在 ListView 中的外部 ScrollViewer 之前,即使看到它们,也是如此。



如果可能的话,我建议用 ItemsControl 替换 ListBox 。但是,这意味着不会有 SelectedItem 属性。如果你需要的话,我建议设置 ScrollViewer.Horizo​​ntalScrollBarVisibility (或者 VerticalScrollBarVisibility )为 。否则,我只能建议重新模板 ListBox 不要包含 ScrollViewer


I am having a problem with scrolling for my WPF application.

Here is the deal. My UI is the following:

The role of my application is to act as a central hub for many applications and launch them. An admin can launch a dump recorded by another user. Therefore, I have a ListView, showing the application list, which is scrollable if needed. I defined a GroupStyle in order to show expanders and emulate a Windows Explorer view. Everything works fine, I just have a problem: when scrolling with the mouse wheel, the component in clear blue ("Launch mode") seems to be catching the focus and stop scrolling. This means especially that if my mouse is anywhere out of this control, the scrolling is okay. But whenever the mouse enters this control, I can't scroll anymore. I tried to modify the property Focusable and set it to False everywhere I could but nothing changed. I'd guess that it is finally not a focus problem. Anybody has an idea on how to avoid the scrolling to be caught by the element?

Here is some (simplified, removed some useless properties so as to make it as clear as possible) XAML for the expander's content:

<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>

And the code for 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>

As you can see, the UcReleaseChooser contains a list of RadioButton lists. I tried to set Focusable & CanContentScroll to False everywhere it seemed appropriate, but the control keeps preventing the main UI to scroll...

I guess I should change another property... Any idea?

Thanks!

解决方案

The problem is the ListBox, or more specifically, the ScrollViewer within the ListBox's template. This is getting your scroll events and consuming them before the outer ScrollViewer in the ListView even sees them.

I would advise replacing the ListBox with an ItemsControl if possible. However, that implies there will be no SelectedItem property. If you need that, I would suggest setting ScrollViewer.HorizontalScrollBarVisibility (or VerticalScrollBarVisibility) to Disabled. Failing that, I can only suggest re-templating ListBox to not contain a ScrollViewer at all.

这篇关于WPF Scroll&amp;焦点转变的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆